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
functionnoBigIntUsingTypeOf(val: number|BigInt): string|number|null{// Type narrowing is not correct, but this code does do what it looks likeif(typeofval==='bigint'){returnnull}else{returnval}}functionnoBigIntUsingInstanceOf(val: number|BigInt): string|number|null{// Type narrowing is correct, but since this code doesn't work, it is actually wrongif(valinstanceofBigInt){returnnull}else{returnval}}
π Actual behavior
typescript believes the typeof val === 'bigint' check does not narrow the type down, when in reality (JS) it does - and similarly for the instanceof case, typescript believes the type to be narrowed down, when reality (JS) it does not work at all
π Expected behavior
typeof val === 'bigint' would narrow the type down to not include BigInt
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
π Search Terms
bigInt typeof, bigint instanceof
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?target=99&ts=5.5.0-dev.20240417#code/FAMwrgdgxgLglgewgAgggQnA5gSQjAVQGc4IsAVATwAcBTAeRAAoA3AQwBsAuVMAWwBGtAE7IAPsky58ASh5EYw0lnG9BI1RDAcOyAN7BkR5AHoTyKnVRthwhAHdlyOEVQIYyKAlu1YAGmQBMA8YAAsXTwQAE1pkKIRaV3jke1C2DzgPDgQEAGtXDjhc2kNjOBBkJhgaWgQK9l0AXmbkAHIBbFIYVpl9UuNjYVoYMGEULR1+5ABfZFoOIliDAYGhkbHkBqnp4B3QSFhEcYxsPEISMjwFNmgGZgaeLXVRCSkzuWQFJTJNfiEX3g6PoDMwWGrWWwOJwRLw+fyBYKfUhQWJhGHRWLxRIQVoeezeXIBTLOVxsWBgTgcSgpOxkKblSoNZwQa63OqSU6yYErIxrUbjbQcbZzBZLKarYb8zacba7YDAIA
π» Code
π Actual behavior
typescript believes the
typeof val === 'bigint'
check does not narrow the type down, when in reality (JS) it does - and similarly for the instanceof case, typescript believes the type to be narrowed down, when reality (JS) it does not work at allπ Expected behavior
typeof val === 'bigint'
would narrow the type down to not include BigIntAdditional information about the issue
No response
The text was updated successfully, but these errors were encountered: