我正在开发一个有角度的应用程序。我的程序运行正常。
但是在我的规格文件中,出现以下错误。
Argument of type '{ type: string; sections: { rjf: { type: string; text: string; depth: number; inlineEntityRanges: any[]; inlineStyleRanges: any[]; }[]; type: string; }[]; }[]' is not assignable to parameter of type 'AreasData[]'.
Type '{ type: string; sections: { rjf: { type: string; text: string; depth: number; inlineEntityRanges: any[]; inlineStyleRanges: any[]; }[]; type: string; }[]; }' is not assignable to type 'AreasData'.
Types of property 'sections' are incompatible.
Property '0' is missing in type '{ rjf: { type: string; text: string; depth: number; inlineEntityRanges: any[]; inlineStyleRanges: any[]; }[]; type: string; }[]' but required in type '[SectionData]'.ts(2345)
这是函数,contentDataGrouping(content: Array<AreasData>) {}
在ts文件中没有错误。
我的规范
it('should group all list and accordion items', () => {
const obj = contentService.contentDataGrouping(CONTENT_SERVICE_INPUT);
expect(JSON.stringify(obj)).toEqual(JSON.stringify(CONTENT_SERVICE_OUTPUT));
});
这是我将其作为输入发送到contentDataGrouping
export const CONTENT_SERVICE_INPUT=[{type:"column",sections:[{rjf:[{type:"heading-1",text:"This is sample",depth:0,inlineEntityRanges:[],inlineStyleRanges:[]}],type:"title"}]},{type:"accordion-item",sections:[{type:"accordion-title",rjf:[{type:"heading-1",text:"This is Accordion Heading 1"}]},{type:"accordion-body",value:"accordion-body2",rjf:[{type:"paragraph",text:"This is Accordion paragraph"}]}]},{type:"accordion-item",sections:[{type:"accordion-title",rjf:[{type:"heading-1",text:"This is Accordion Heading 2"}]},{type:"accordion-body",value:"accordion-body2",rjf:[{type:"paragraph",text:"This is Accordion paragraph 2"}]}]}];
下面是我的类型,
export interface AreasData {
type?: string | null;
sections: [SectionData];
items?: (AreasData)[] | null;
}
export interface SectionData {
type?: string | null;
rjf: [RJFData];
}
export interface RJFData {
depth?: number | null;
inlineEntityRanges?: EntityData[];
inlineStyleRanges?: StyleData[];
text: string | null;
type: string | null;
data?: any;
}
请帮助我在这里做错了。
答案 0 :(得分:0)
您在各节下的注册未包含在[]中。
将项目添加到数组或将类型更改为rjft:RFJTData