Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

typescript

ide

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));
like image 334
T. Jami Avatar asked Jul 28 '26 11:07

T. Jami


1 Answers

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

like image 195
Matthieu Riegler Avatar answered Jul 31 '26 00:07

Matthieu Riegler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!