为什么在针对 esNext 时不能将 bigints 与打字稿一起使用?



这是我的typescript配置

$ npx tsc --showConfig
{
"compilerOptions": {
"target": "es2021",
"lib": [],
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"files": [
"./index.ts",        ]
}

这是index.ts:

const a = 1n;

当我尝试运行tsc时,我得到这个输出

$ npx tsc index.ts
error TS2737: BigInt literals are not available when targeting lower than ES2020.

为什么我得到这个错误?我的tsconfig文件有什么问题吗?

如果使用文件名作为参数运行tsc,则tsconfig.json将被忽略。

使用--target参数,或者不使用index.ts

运行tsc

最新更新