Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use ES2023 methods in TypeScript?

I want to use the ES2023 toReversed() method on TypeScript, but I'm getting this error when I'm building my Next.js project:

Type error: Property 'toReversed' does not exist on type 'Job[]'. Did you mean 'reverse'?

I tried updating TypeScript to newest version and adding "ES2023" and "ES2023.Array" into lib in tsconfig.json but it didn't work.

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "lib": ["dom", "dom.iterable", "esnext", "ES2023", "ES2023.Array"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "components/Home/about.tsx", "components/Socials/Icons/socialIcons.tsx", "components/Socials/socials.tsx", "pages/_app.tsx", "functions/formatDate.ts"],
  "exclude": ["node_modules"]
}

I already saw This question, but he did not add "ES2023" and "ES2023.Array" into his tsconfig.json file, and I don't know why I'm still getting this error even though I updated my tsconfig.json file.

Why do I keep getting this error with ES2023 configurations in my tsconfig.json file?

like image 359
Ali Navidi Avatar asked Nov 30 '25 02:11

Ali Navidi


2 Answers

This issue has been solved with TypeScript version 5.5, you just need to add ESNext into lib property of tsconfig.json like this:

"lib": ["ESNext", "dom", "dom.iterable"],

Here is a YouTube video for more info on version 5.5: https://www.youtube.com/watch?v=FhT87_CqPug

like image 163
Ali Navidi Avatar answered Dec 02 '25 16:12

Ali Navidi


Since typescript 5.2 is now available having "ES2023" or "ES2023.Array" in the "lib" property of your tsconfig.json should now work.

like image 35
Simon Bergot Avatar answered Dec 02 '25 15:12

Simon Bergot



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!