Home > Net >  TS Error - Property 'at' does not exist on type 'string[]
TS Error - Property 'at' does not exist on type 'string[]

Time:03-11

I dont know if this is a bug or something, but I simply cant remove the TS error in my IDE (Webstorm).

The error appears when I am using Array.prototype.at() on any kind of array.

tsconfig.json:

"lib": [
        "DOM",
        "ES2020",
        "ESNext"
    ],

But this seems not to work, I also added ES2021 - ES2015 but the error keeps on. It does work when I compile it, but I just get the error in the IDE.

Does anybody know how to fix this?

const arr = ["hello", 5, true, {name: "test"}];

console.log(arr.at(0));
console.log(arr.at(1));
console.log(arr.at(-1));
console.log(arr.at(-2));

CodePudding user response:

Array.at requires ES2022 target which is available from TS 4.6 onwards.

  • Related