如何在 TypeScript 中使用 ES2023 方法?

Ali*_*idi 13 javascript typescript reactjs next.js

我想toReversed()在 TypeScript 上使用 ES2023 方法,但在构建 Next.js 项目时遇到此错误:

类型错误:类型“Job[]”上不存在属性“toReversed”。您指的是 'reverse' 吗?

我尝试将 TypeScript 更新到最新版本并添加"ES2023""ES2023.Array"进去libtsconfig.json但它不起作用。

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"]
}
Run Code Online (Sandbox Code Playgroud)

我已经看到了This Question,但他没有将"ES2023"和添加"ES2023.Array"到他的tsconfig.json文件中,而且我不知道为什么即使我更新了tsconfig.json文件,我仍然收到此错误。

为什么我的tsconfig.json文件中的 ES2023 配置不断出现此错误?

Sim*_*got 1

由于 Typescript 5.2 现在可用,因此 tsconfig.json 的“lib”属性中包含“ES2023”或“ES2023.Array”现在应该可以工作。

  • 嗯,我在 TS `5.2.2` 上,并在 `ES2023` 下面看到红色波浪线 (6认同)