错误:Property 'Control' is missing in type '() => Controls' but required in type 'Controls'.
export class Controls {
Control: Control[];
}
page.Sections.push({
....
Controls: () => {
const c = new Controls();
c.Control = new Array<Ctrl>();
section.VisualComponents.forEach(vc => {
c.Control.push({
....
....
});
});
return c;
}
});
我在做什么错了?
答案 0 :(得分:1)
您必须具有Controls[]
数组,但要分配一个函数Controls: () => {
:
export class Controls {
Control: Control[]; /// HERE
}
page.Sections.push({
....
Controls: () => { // HERE
const c = new Controls();
c.Control = new Array<Ctrl>();
section.VisualComponents.forEach(vc => {
c.Control.push({
....
....
});
});
return c;
}
});
调用函数以获取其返回值,例如:
const createControls = () => {
const c = new Controls();
c.Control = new Array<Ctrl>();
section.VisualComponents.forEach(vc => {
c.Control.push({
....
....
});
});
return c;
};
export class Controls {
Control: Control[];
}
page.Sections.push({
....
Controls: createControls()
});