需要什么约束来检查一个类型必须是一个数组,不管它的元素类型是什么?
以下代码失败:
function test<A extends any[]>(): A {
const array: any[] = [1, 2]
return array;
}
该错误是一个约束错误:
Type 'any[]' is not assignable to type 'A'.
'any[]' is assignable to the constraint of type 'A', but 'A' could be instantiated with a different subtype of constraint 'any[]'.(2322)