您可以向类型化数组视图构造函数传递数字、JavaScript本机数组或另一种类型(以及其他内容
const a = new Int32Array(3);
const b = new Int32Array([1, 2, 3]);
const c = new Int32Array(new Int32Array([1, 2, 3]));
考虑到这一点,我希望这份Typescript 能奏效
function make(data: number | number[] | Int32Array) {
return new Int32Array(data);
}
但失败的原因是
No overload matches this call. The last overload gave the following error. Argument of type 'number | Int32Array | number[]' is not assignable to parameter of type 'ArrayBufferLike'. Type 'number' is not assignable to type 'ArrayBufferLike'.(2769)
我做错什么了吗?这是已知的限制吗?