如何在 TypeScript 中使用 ES2023 方法?

huangapple go评论81阅读模式
英文:

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?

英文:

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?

答案1

得分: 2

"Since TypeScript 5.2 is now available, 在你的 tsconfig.json 的 'lib' 属性中包含 'ES2023' 或 'ES2023.Array' 现在应该可以正常工作。"

英文:

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

huangapple
  • 本文由 发表于 2023年7月18日 15:53:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76710595.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定