javascriptreactjstypescriptnext.js

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?


Solution

  • 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