【问题标题】:Why can't I use bigints with typescript when targetting esNext?以 esNext 为目标时,为什么我不能将 bigints 与 typescript 一起使用?
【发布时间】:2021-10-28 18:40:45
【问题描述】:

这是我的打字稿配置

$ 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 文件有什么问题吗?

【问题讨论】:

  • 您使用的是什么打字稿版本?它可能不知道 ES2021。

标签: typescript tsconfig bigint


【解决方案1】:

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

要么使用--target 参数,要么运行tsc 不使用 index.ts

【讨论】:

    猜你喜欢
    • 2019-08-27
    • 2020-08-26
    • 2013-07-02
    • 2015-11-08
    • 2013-08-24
    • 2017-01-31
    • 2020-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多