为什么在以 esNext 为目标时我不能将 bigints 与 typescript 一起使用?
Why can't I use bigints with typescript when targetting esNext?
这是我的打字稿配置
$ 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
参数,要么 运行 tsc
without index.ts
这是我的打字稿配置
$ 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
参数,要么 运行 tsc
without index.ts