Missing Properties

13 Views Asked by At

im new to typescript i want to know how i get this error as far as i know i included all of the properties

Type '{ type: "text"; sender: string; recipient: string; timestamp: number; content: string; status: Status.SENT; }' is missing the following properties from type 'Text': wholeText, splitText, data, length, and 62 more.ts(2740)

and this is my code

enum Status {
    SENT = "Sent",
    DELIVERED = "Delivered",
    READ = "Read",
}

interface Require {
    sender: string;
    recipient: string;
    timestamp: number;
    status: Status;
}

interface Text extends Require {
    type: "text";
    content: string;
}

const textMessage: Text = {
    type: "text",
    sender: "Bob",
    recipient: "Alice",
    timestamp: Date.now(),
    content: "Hello this is bob!",
    status : Status.SENT
};
1

There are 1 best solutions below

0
emptyjar On BEST ANSWER

You're running afoul of the existing Text type https://developer.mozilla.org/en-US/docs/Web/API/Text

If you rename your class to something unique

interface MyText extends Require {
    type: "text";
    content: string;
}

const textMessage: MyText = {
    type: "text",
    sender: "Bob",
    recipient: "Alice",
    timestamp: Date.now(),
    content: "Hello this is bob!",
    status : Status.SENT
};

you obtain a new type.