-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use bigint with any in certain arithmetic expressions #41741
Comments
This was intentional since, unlike other operands, operations like |
@RyanCavanaugh I disagree. Since |
Another example: var x: any = 0n
var y = -x Now, the type of |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
I am getting this error: TypeScript version 4.1.3. I can understand throwing an error for applying arithmetic to mixed types since BigInt and number are not compatible, but this is a BigInt plus a BigInt. For some background the operation is question is: details.size = details.size + size;
// details.size is defined as a BigInt
// size comes from "size" property of Node type BigIntStats EDIT: The problem is that @types/node was out of date. I updated to version 14.14.20 and it reports BigIntStats.size as type EDIT2: Seems I needed to read the documentation: |
I can understand the design decision to not allow "potentially mixed computations", but this last example is clearly wrong typing, they can't be serious this is "working as intended". The original argument was to "throw rather than produce possibly-useful values" (@RyanCavanaugh), but this example shows that there are cases where the typing is too "optimistic". |
TypeScript Version: 4.2.0-dev.20201130
Search Terms: is:issue bigint
Code
Expected behavior:
The code should compile without errors, because
x
could be abigint
.Actual behavior:
Each of the expressions fails to typecheck:
error TS2365: Operator '+' cannot be applied to types 'number' and 'bigint'.
.Playground Link: link
Related Issues: none.
The text was updated successfully, but these errors were encountered: