Using BigInt in TypeScript

后端 未结 1 1409
慢半拍i
慢半拍i 2021-01-12 14:32

I believe I should be able to use BigInt now in TypeScript...but changing some code base to use it and I get \"Cannot find name \'BigInt\'. (2304)\" any thought on why I am

相关标签:
1条回答
  • 2021-01-12 15:15

    BigInt support has been added on TypeScript 3.2; make sure your version is compatible.

    But on top of that, you need to decide how BigInt will be supported on the context of your script - will you provide polyfills, or will you only run your script on environments that are guaranteed to have BigInt support?

    This means you will need esnext as your build target (likely on tsconfig.json's target field), since BigInt is not compatible with previous ECMAScript versions.

    If you do include a BigInt polyfill, you can use esnext.bigint as part of the lib field during transpilation. This adds the needed definitions to the process.

    0 讨论(0)
提交回复
热议问题