-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed as not planned
Closed as not planned
Copy link
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
⚙ Compilation target
ES2020
⚙ Library
TypeScript
Missing / Incorrect Definition
interface BigIntConstructor {
// wrong
(value: bigint | boolean | number | string): bigint;
// right
(value: bigint | BigInt | boolean | Boolean | number | Number | string | String): bigint;
}
Sample Code
declare const n: unknown
if (n instanceof BigInt) {
BigInt(n)
// ^? TS2345: Argument of type BigInt is not assignable to parameter of type string | number | bigint | boolean
}
// ----
function foo(a: BigInt) {
BigInt(a)
// ^? TS2345: Argument of type BigInt is not assignable to parameter of type string | number | bigint | boolean
}
foo(Object(BigInt(1)))
Documentation Link
We can see in 21.2.1.1 BigInt ( value ) that 2. Let prim be ? ToPrimitive(value, NUMBER).
corresponds to our situation and triggers ToPrimitive
.
ToPrimitive
attempts to retrieve the valueOf
method of the Object
. For BigInt
, Number
, String
, and Boolean
, this method exists, allowing us to obtain a corresponding primitive value. Then, based on the preferredType
of NUMBER
, it is further converted to a number.
Our problem is essentially answered here, indicating that we should support Boxed Types
as input.

about
MartinJohns
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug