first i use fill function
const range = new Array(layernum.length).fill(NaN);//[ts] Property 'fill' does not exist on type 'any[]'
to deal with this problem,i use
const range = new Int32Array(layernum.length).fill(NaN);
instead
while,it cause another problem
let layer = range.map(e => range.map(e => e)); //Type 'Int32Array' is not assignable to type 'number'
so how to use prototype in Typescript
If you don't want/can't use the lib.es6.d.ts
, then you can update the compiler with the method signature:
declare global {
interface Array<T> {
fill(value: T, start?: number, end?: number): this;
}
}
The fill
method of array exists only in ES6 or above. In order for typescript to recognize the propper ES6 version of the Array class you need to make sure you include es6
in the lib
property of your tsconfig.json
. For example:
{
"compilerOptions": {
"target": "es5",
"lib" : ["es6", "dom"]
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With