类型中缺少属性“0” [英] Property '0' is missing in type
问题描述
我有这样的界面
export interface Details {
Name: [{
First: string;
Last: string;
}];
}
我有一个可观察的配置变量
I have a observable config variable
Configuration: KnockoutObservable<Details> = ko.observable<Details>();
我想在构造函数中为它赋值如下 -
and I would like to assign it a value in the constructor as follows -
config = {
Name: [{
First: "ABC",
Last: "DEF"
},
{
First: "LMN",
Last: "XYZ"
}]
};
this.Configuration(config);
我收到错误:
财产类型'名称'不兼容,属性'0'缺少
类型。
Types of property 'Name' is incompatible and property '0' is missing in type.
输入'{First:串;最后:字符串; } []'不能赋值为'[{
First:string;最后:字符串; }]'
Type '{ First:string; Last:string; }[]' is not assignable to type '[{ First: string; Last:string; }]'
我无法控制更改界面,因为它正在其他地方使用。初始化此配置变量的正确方法是什么?
I don't have control on changing the interface as it is being used elsewhere. What is the correct way to initialize this config variable ?
提前致谢。
推荐答案
我遇到了同样的问题,并通过将界面更改为:
I came across the same issue and got around it by changing the interface to:
interface Details {
Name: {
First: string;
Last: string;
}[];
}
我知道您可能不希望界面发生变化,但希望这有助于任何人在这种情况下。
I know you may not want the interface changed but hope this helps for anyone that is in this situation.
这篇关于类型中缺少属性“0”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!