最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the difference between 'bigint' (lowercase) and 'BigInt'? - Stack Overflow

programmeradmin1浏览0评论

So I am trying to update some typescript code that uses external library for big numbers to BigInt (ES2020) and linter is plaining a lot. I don't really understand what is going on here.

It looks like there are two different types - 'bigint' and 'BigInt' and this two are not patible with each other.

when I change partialValue type to 'bigint' the error disappears. Does this mean I should use 'bigint' instead of 'BigInt'? It is 'BigInt' in the documentation. Thats pretty confusing I must say.

So I am trying to update some typescript code that uses external library for big numbers to BigInt (ES2020) and linter is plaining a lot. I don't really understand what is going on here.

It looks like there are two different types - 'bigint' and 'BigInt' and this two are not patible with each other.

when I change partialValue type to 'bigint' the error disappears. Does this mean I should use 'bigint' instead of 'BigInt'? It is 'BigInt' in the documentation. Thats pretty confusing I must say.

Share Improve this question asked Jun 14, 2023 at 20:25 HufsaHufsa 891 silver badge3 bronze badges 2
  • Check out this SO question: stackoverflow./questions/15487220/… – LarryTLlama Commented Jun 14, 2023 at 20:27
  • stackoverflow./questions/75202528/… – epascarello Commented Jun 14, 2023 at 20:28
Add a ment  | 

1 Answer 1

Reset to default 12

bigint' (lowercase) is a built-in primitive type introduced in ECMAScript 2020 (ES2020) to represent arbitrary precision integers. It is used to work with large integers that cannot be accurately represented using the regular 'number' type.

On the other hand, 'BigInt' (uppercase) is the constructor function for creating 'bigint' instances. It is part of the global namespace and allows you to create 'bigint' values using the 'BigInt()' function.

The confusion arises because the 'bigint' primitive type shares the same name with the 'BigInt' constructor function. However, they are not the same thing and cannot be used interchangeably.

In TypeScript, when you use the lowercase 'bigint' as a type annotation, you are explicitly specifying that a variable should be of type 'bigint'. For example:

let myNumber: bigint = BigInt(12345);

In the above code, 'myNumber' is explicitly declared as a 'bigint' using the lowercase type annotation.

When you use the uppercase 'BigInt', it refers to the constructor function and not the primitive type. If you try to use 'BigInt' as a type annotation, TypeScript treats it as a different type that is not patible with 'bigint'. This is why you're seeing errors when you change the type to 'BigInt'.

发布评论

评论列表(0)

  1. 暂无评论