The type of bitwise operations on 'any' operands should be 'number | bigint'
See original GitHub issueBug Report
๐ Search Terms
- bigint
- bitwise
๐ Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about bigint.
โฏ Playground Link
๐ป Code
//@target: ES2020
const v1 = 1n as any;
const v2 = 2n as never;
const v3 = v1 | v2; // v3 should be typed (number | bigint), but is number
๐ Actual behavior
The result of the bitwise operations &
, |
, ^
and ~
is assumed to be a number
when all the operands have unspecified type, like any
or never
.
๐ Expected behavior
The result of bitwise operations with unspecified type operands should be number | bigint
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Bitwise AND (&) - JavaScript - MDN Web Docs
The bitwise AND (&) operator returns a 1 in each bit position for which the corresponding bits of both operands are 1s.
Read more >INT13-C. Use bitwise operators only on unsigned operands
Bitwise operators should be used only with unsigned integer operands, as the results of bitwise operations on signed integers areย ...
Read more >Bitwise operators (Transact-SQL) - SQL Server - Microsoft Learn
Bitwise operators perform bit manipulations between two expressions of any of the data types of the integer data type category.
Read more >BigInt - Grain Docs
Functions for converting between Numbers and the BigInt type. ... Converts a Number to a BigInt. ... Returns the absolute value of the...
Read more >Expression types - IBM
Each of the bitwise operators and (&) , or (|), and exclusive or (^) perform a bitwise operation on two operands, returning a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Clearly TypeScript thinks that certain operators can produce nothing but a number, which used to be true (i.e.
-value
), but no longer holds in times of bigint.Here is a relevant recent example: