Arithmetic operations on type-parameters subtyping bigint
are incorrectly inferred to have type number
#61429
Labels
Milestone
bigint
are incorrectly inferred to have type number
#61429
🔎 Search Terms
bigint, operator, arithmetic, number, subtype, extend, generic, type parameter, incorrect, inference, inferred type, operation, 2365, TS2365
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?target=99&ts=5.8.2#code/GYVwdgxgLglg9mABAIxlAzgUygSTFTAJy2gB4AhNdRTADwLABNrUBzGfAPgAoBDALkSUMAGhSDh6AJSCwIALbIiiAN4AoRJsQB6bYg4FimaPCQxqHYEUKZGiKHEQALXgDdM9gJ4AHDwAM5RSI-REJeKCdlCN4kPzYDPw0tCAR0KH18IhJYBEQAXkReRAAyFABuNSTNXUQAVgA6AA56gCZQzG84QgxEMEcoHw9rLpEqnT1kEHSiwnBYeSHCQi7EOAgIEGJ+MZqAbQBRACVDgF1BAGEYvvT5GFohGFY8aaZViKjB9DEQLBpabwANjAIGhECkwO5iKZqGMbFBNmZMkYTLkALSIACMFQAvpVweg4ADMPUAXBWNxUBhsM8ssYoNwAOxgMS1MBSKQVIA
💻 Code
🙁 Actual behavior
intersection
is inferred to have typenumber
. As a result, no type errors are reported.When run, the code encounters a TypeError because
intersection - 1
attempts to perform arithmetic on a bigint and a number:🙂 Expected behavior
intersection
should be inferred to have typebigint
.Thus the operation
intersection - 1
should report a type error:Additional information about the issue
This issue is most likely to be hit when branding
bigint
, but it could also appear in other situations, such as using subtypes which are unions of literals.I found some issues that are similar, but have a different scope. These issues were closed as intended, but in these issues, larger type bounds which include
bigint
but also includenumber
(such asany
orbigint | number
) are used:number
, notnumber | bigint
#49558The text was updated successfully, but these errors were encountered: