As per the documentation on MDN Web Docs Array.prototype#at method, it should be a valid function. However, when attempting to compile in TypeScript, an error occurs stating that the method does not exist.
public at(index: number): V {
index = Math.floor(index);
const arr = [...this.values()];
return arr.at(index);
}
The console output from tsc shows the issue: https://i.sstatic.net/6ONKS.png
Using bracket notation is not an option as the method needs to handle negative numbers. Adjusting the target setting in the tsconfig.json file to ESNext, ES2021, and ES6 has been tried with no success. The lib option also did not resolve the problem.
json
// tsconfig.json
{
"compilerOptions": {
"target": "ES2021",
"outDir": "./dist",
"declaration": true,
"declarationDir": "./typings",
"lib": ["ES2021", "ESNext"]
}
}
Seeking guidance on resolving this issue. Any help or advice would be greatly appreciated.