I am getting a problem with Typescript interfaces. I am trying to cast one object (with some fields missing such as createdBy) to another object but my casting is not working.
I hope someone can help.
Here are the interface files that I have:
interface IWord {
ascii?: number;
awl570?: boolean;
awl570Sublist?: number;
categoryId: number;
frequency?: number;
groupId: number;
lessonId: number;
name: string;
nawl963?: boolean;
nawl963D?: number;
nawl963Sfi?: number;
nawl963U?: number;
statusId: number;
syllables?: string;
toeflMcG400?: boolean;
toeic?: boolean;
wordForms: IWordForm[];
wordId: number;
createdById: number;
createdDate: string;
modifiedById: number;
modifiedDate: string;
}
interface IWordForm {
definition: string;
posId: number;
sampleSentences: [ISampleSentence];
sourceId: number;
statusId: number;
synonyms: [ISynonym];
wordFormId: number;
wordId: number;
createdById: number;
createdDate: string;
modifiedById: number;
modifiedDate: string;
}
I am trying to create this:
var wos.word = <IWord>{
categoryId: 1,
lessonId: 1,
name: null,
groupId: 1,
statusId: Status.Clean,
toefl: true,
wordForms: <IWordForm[]>[],
wordId: $stateParams.wordId
}
But getting the following error:
Severity Code Description Project File Line Suppression State Error TS2352 Neither type '{ categoryId: number; lessonId: number; name: null; groupId: number; statusId: Status; toefl: boo...' nor type 'IWord' is assignable to the other. Property 'createdById' is missing in type '{ categoryId: number; lessonId: number; name: null; groupId: number; statusId: Status; toefl: boo...'. admin C:\H\admin\admin\app\routes\words.ts 102 Active