next.js 如何在TypeScript中使用ES2023方法?

olhwl3o2  于 5个月前  发布在  TypeScript
关注(0)|答案(1)|浏览(49)

我想在TypeScript上使用ES2023 toReversed()方法,但是当我构建Next.js项目时,我得到了这个错误:
类型错误:属性“toReversed”在类型“Job[作业]”上不存在。您的意思是“reverse”吗?
我尝试将TypeScript更新到最新版本,并在tsconfig.json中将"ES2023""ES2023.Array"添加到lib中,但它不起作用。

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"]
}

字符串
我已经看到了This question,但他没有添加"ES2023""ES2023.Array"到他的tsconfig.json文件,我不知道为什么我仍然得到这个错误,即使我更新了我的tsconfig.json文件。
为什么我的tsconfig.json文件中的ES2023配置一直出现此错误?

nnt7mjpx

nnt7mjpx1#

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

相关问题