【发布时间】:2023-03-29 04:23:01
【问题描述】:
我想要一个类型来表示一个坐标。我应用于接口的类型适用于对象,但不适用于类。
type ICoord = [number, number]
type MyInterface = {
a: ICoord
}
var obj: MyInterface = { // works
a: [0, 0]
}
class C implements MyInterface { // gets below compilation error
a = [0, 0]
}
Property 'a' in type 'C' is not assignable to the same property in base type 'MyInterface'. Type 'number[]' is missing the following properties from type '[number, number]': 0, 1
为什么我不能将[0, 0] 分配给a?
【问题讨论】:
标签: javascript typescript types