你好,我想创建一个像这样的对象类型:
const z = {
name: { // this one is special
buty: ['qqqq']
},
lipa: ['xxx'],
// more keys here
};
基本上,它就像这样一个对象
type Test = {
[key: string]: string[]
}
除了一个小例外,它总是有一个键名称和稍微不同的值。
type Special = {
name: {
[key: string]: string[]
}
}
但是当我尝试合并这两种类型时
type Test =
{ [key: string]: string[] } &
{ name: { [key: string]: string[] } };
const z: Test = {
name: { // this one is special
buty: ['qqqq']
},
lipa: ['xxx'],
// more keys here
};
我遇到了一个错误:Type '{ buty: string[]; }' is missing the following properties from type 'string[]': length, pop, push, concat, and 26 more.(2322)
。
是否可能为这样的对象创建类型?