我的界面是这样的
export interface Details {
Name: [{
First: string;
Last: string;
}];
}
我有一个可观察的配置变量:
Configuration: KnockoutObservable<Details> = ko.observable<Details>();
我想在构造函数中为其分配一个值,如下所示:
config = {
Name: [{
First: "ABC",
Last: "DEF"
},
{
First: "LMN",
Last: "XYZ"
}]
};
this.Configuration(config);
我收到一个错误:
Types of property 'Name' is incompatible and property '0' is missing in type.
Type '{ First:string; Last:string; }[]' is not assignable to
type '[{ First: string; Last:string; }]'
我无法控制更改界面,因为它正在其他地方使用。
初始化此配置变量的正确方法是什么?
提前致谢。
我遇到了同样的问题,并通过将界面更改为来解决它:
interface Details {
Name: {
First: string;
Last: string;
}[];
}
我知道您可能不希望更改界面,但希望这对遇到这种情况的人有所帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)