You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Applying an unary minus on an any variable infers the type to number (as can be seen in the "hat-question mark" comments or the .D.TS tab for x, conv, and r). The inferred type for the constants x and r is thus wrong (they actually contain a BigInt value).
Unary minus on a number correctly infers number, and (more importantly) unary minus on a bigint correctly infers bigint. Same for unary minus on a number | bigint which infers number | bigint.
π Expected behavior
Applying an unary minus on an any variable should infer the type to number | bigint.
π Search Terms
"unary minus", "negate bigint"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?target=99&ts=5.7.2#code/MYewdgzgLgBARjAvDAtACgIxgJQG4BQA9ITKTAHoD8+okscATEqnAcWRdTeNDGM+gx4iJMlW50+TZCjBtRpcRN4BDAFwwVYAJ7NWIjuNq8AHgJXzDXY7FoA3Zmjsat27EgB8qO5bHUbMABOzPZocMLsfsq24HbSME4aYACuALZwAKbBAD7wAJYA5nlgUO6IXig+BlEBgfH2DGERCpz4QA
π» Code
π Actual behavior
Applying an unary minus on an
any
variable infers the type tonumber
(as can be seen in the "hat-question mark" comments or the .D.TS tab forx
,conv
, andr
). The inferred type for the constantsx
andr
is thus wrong (they actually contain a BigInt value).Unary minus on a
number
correctly infersnumber
, and (more importantly) unary minus on abigint
correctly infersbigint
. Same for unary minus on anumber | bigint
which infersnumber | bigint
.π Expected behavior
Applying an unary minus on an
any
variable should infer the type tonumber | bigint
.ECMAScript specifies (https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-unary-minus-operator) unary minus as doing a
ToNumeric
(which returns either a Number of a BigInt) and then applying the appropriateunaryMinus
abstract operation depending on the type of the value. The result is thus either a Number or a BigInt.(the unary plus operator however converts to Number values only)
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: