英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论