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.
- 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
1 Answer
Reset to default 12bigint' (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'.