Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
Property "at" does not exist on Array

According to MDN Web Docs Array.prototype#at, is a valid method. But for some reasons, TypeScript refuses to compile, stating that it does not exist.

public at(index: number): V {
  index = Math.floor(index);
  const arr = [...this.values()];
  return arr.at(index);
}

Console output from tsc: Typescript Complains more

I can't use bracket notation, since the method is meant to be able to handle negative numbers. I've tried lots of things, including setting the target in the tsconfig.json file to ESNext, ES2021, and ES6 but to no avail. The lib option doesn't help either.

json

// tsconfig.json
{
  "compilerOptions": {
    "target": "ES2021",
    "outDir": "./dist",
    "declaration": true,
    "declarationDir": "./typings",
    "lib": ["ES2021", "ESNext"]
  }
}

What can I do? Am I doing something wrong?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

According to MDN Web Docs Array.prototype#at, is a valid method.

MDN does not get to decide what is part of TypeScript and what isn't. The TypeScript developers do that.

Whether or not MDN says something is a "valid method" is relevant to Mozilla, and only Mozilla, but has no bearing on TypeScript.

But for some reasons, TypeScript refuses to compile, stating that it does not exist.

That's because the method doesn't exist in any ECMAScript version supported by TypeScript.

I've tried lots of things, including setting the target in the tsconfig.json file to ESNext, ES2021, and ES6 but to no avail.

That's because the method doesn't exist in either ECMAScript 6 or ECMAScript 2021. It does exist in ES2022 (which is what ESNext is at the moment), but it was only added eight weeks ago, and thus after TypeScript 4.4 was finalized (and possibly also too late for TypeScript 4.5).

The lib option doesn't help either.

Again, that's because the method does not exist in any library version supported by TypeScript at the moment.

Even in the current main branch, which is going to become TypeScript 4.6, lib/lib.esnext.d.ts only corresponds to ECMAScript 2021 + the latest Internationalization extensions.

What can I do? Am I doing something wrong?

You can wait until the method actually becomes part of a released version of ECMAScript and/or TypeScript.

about 4 years ago · Juan Pablo Isaza Report

0

Array#at is indeed a new method available only in ESNext or by using a polyfill. If you're using latter, you can just augment global array interface like this:

declare global {         
   interface Array<T> {                     
      at(index: number): T;
   }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!