You told the compiler that article
is of type { title: string, text: string }
, but then you assign an empty object ( {}
) that does not have both title
and text
, so the compiler complains.
You can use a type statement to tell the compiler that this is normal:
let article: { title: string, text: string } = {} as { title: string, text: string };
You can also put this in an alias like:
type MyType = { title: string, text: string }; let article: MyType = {} as MyType;
And since you are using a type statement, you can simply:
let article = {} as MyType;
source share