I have the following Typescript interface files and I am trying to create a simple minimal object of type Word with a WordForm object inside of it:
interface IWord {
categoryId: number;
createdBy: number;
createdDate: any;
groupId: number;
ielts: boolean;
lessonId: number;
modifiedBy: number;
modifiedDate: any;
toefl: boolean;
toeic: boolean;
wordForms: IWordForm[];
wordId: string;
}
interface IWordForm {
createdBy: number;
createdDate: any;
definition: string;
modifiedBy: number;
modifiedDate: any;
posId: number;
primary: boolean;
sample1: string;
sample2: string;
sample3: string;
sample4: string;
sample5: string;
synoym: string;
wordFormId: string;
wordId: string;
}
This works okay:
wos.word = <IWord>{
categoryId: 1,
lessonId: 1,
groupId: 1,
toefl: true
}
But this give me an error:
wos.word = <IWord>{
categoryId: 1,
lessonId: 1,
groupId: 1,
toefl: true,
wordForm: <IWordForm>{
posId: 1
}
}
Severity Code Description Project File Line Suppression State Error TS2352 Neither type '{ categoryId: number; lessonId: number; groupId: number; toefl: boolean; wordForm: IWordForm; }' nor type 'IWord' is assignable to the other. Property 'createdBy' is missing in type '{ categoryId: number; lessonId: number; groupId: number; toefl: boolean; wordForm: IWordForm; }'. admin C:\H\admin\admin\app\routes\words.ts 76 Active
Severity Code Description Project File Line Suppression State Error Build: Neither type '{ categoryId: number; lessonId: number; groupId: number; toefl: boolean; wordForm: IWordForm; }' nor type 'IWord' is assignable to the other. admin C:\H\admin\admin\app\routes\words.ts 76
Can someone help and tell me how I can create a word object with a word form inside of it? Note that I know a lot of the parameters are missing in my assignment but by casting I think this should still work.