我的 typescript 代码库中有一堆这样的代码......
export interface SomeType {
name: string;
}
export interface SomeComposedType {
things: [SomeType];
}
这一直工作正常,但后来我开始遇到问题Property '0' is missing in type
和
Argument of type 'SomeType[]' is not assignable to parameter of type '[SomeType]'
我现在真的很困惑这个。我很确定
let x:SomeType[] = []
相当于let x: Array<SomeType> = []
但是let x:[SomeType] = []
也等价和正确?
最佳答案
号[SomeType]
代表一个 tuple type ,即一个只有 SomeType
一个元素的数组[string, number]
例如,将匹配一个数组,如 ["test", 0]
关于typescript - 是 :[Interface] a valid array definition in Typescript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63625736/