不知道如何如何fomulate的问题,但这样的话:TS:为什么可以将无效类型分配给泛型类型变量?
interface X {
some: number
}
let arr1: Array<X> = Array.from([{ some: 1, another: 2 }]) // no error
let arr2: Array<X> = Array.from<X>([{ some: 1, another: 2 }]) // will error
错误:
Argument of type '{ some: number; another: number; }[]' is not assignable to parameter of type 'ArrayLike<X>'.
Index signatures are incompatible.
Type '{ some: number; another: number; }' is not assignable to type 'X'.
Object literal may only specify known properties, and 'another' does not exist in type 'X'.
为什么在第一种情况下没有任何错误(没有类型的可比性检查),是由设计还是有这个问题?
此限制不限于数组,并在[本答案](http://stackoverflow.com/a/31816062/43848)中有详细解释, – artem