microsoft / microsoft/TypeScript

The type of bitwise operations on 'any' operands should be 'number | bigint'

Open
#42,125 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Has Repro Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Bug 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

Workbench Repro

💻 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript Workbench Repro and the provided ES2020 code to confirm how any and never operands are typed for &, |, ^, and ~. Trace the compiler's bitwise-operation type-checking entry point and verify that unspecified operands produce number | bigint rather than number.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.