π Search Terms
bigint negative zero template
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about bigint
β― Playground Link
https://www.typescriptlang.org/play/?target=99&ts=5.6.3#code/C4TwDgpgBACg9gZwFoQE5ygXigBgHYDcAUKJFAHIQDmK6WUAtPgVK2+x5wPRdQD8AQiI82APT5EAxnDwJgUMAC8AXLES0M2JoSky5UPCorUN9ZkRLhoAZWCpKNNJqgADACQBvbQF8Xnf1AigsK8rOKWZLaoAEIAllQAknjy2O4eeACuALYARmi+urLyAB6qUXGJyfQAREzVLAEcQUIR0DAAhqgIEBVJwAA8ACpQEMXAEHgAJgiunjnxscm+AHz0w6PjUzNpiwBmaFB9I2MT01DzVIvAvvyHVap4EABuaK1qCLHAsS8A8o-0HS6PXifX6AHIAIxg5YhMQSUjQBztL6-f7YQHdXrJcEMKEwkRheFWd6fb4QUzozqYkHYsE4aGwwlvJEo8lOAFU4GVAZgpjQtjNRlQcRAA
π» Code
type PosZero = 0n;
type NegZero = -0n; // ?!
// ^? - type NegZero = 0n
const pz: PosZero = -0n;
const nz: NegZero = 0n;
type StrNegZero = `${-0n}` // ?!
// ^? - type StrNegZero = "0"
type StrBigInt = `${number}`
const x: StrBigInt = "-0"; // ?!
type ParseBigInt<T extends `${bigint}`> = T extends `${infer Int extends bigint}` ? Int : never
type PositiveOne = ParseBigInt<'1'>
// ^? - type PositiveOne = 1n
type NegativeOne = ParseBigInt<'-1'>
// ^? - type NegativeOne = -1n
type PositiveZero = ParseBigInt<'0'>
// ^? - type PositiveZero = 0n
type NegativeZero = ParseBigInt<'-0'> // ?!
// ^? - type NegativeZero = bigint
π Actual behavior
-0n is a valid and evalutates to 0n, and "-0" matches `${bigint}`, but `${-0n}` evalutates to "0", and "-0" is not successfully inferred as 0n
π Expected behavior
-0n should either not exist, or it should be handled consistently with other bigint literals.
Either:
-0n should fail, and "-0" should not match `${bigint}`, because -0n is not a valid bigint value, and thus no such bigint stringifies to -0.
"-0" should be inferred to contain 0n/-0n, because -0n is valid syntax that evalutates to 0n.
Additional information about the issue
Credit to mkantor and sinclair in the TypeScript Community for extra examples.
π Search Terms
bigint negative zero template
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?target=99&ts=5.6.3#code/C4TwDgpgBACg9gZwFoQE5ygXigBgHYDcAUKJFAHIQDmK6WUAtPgVK2+x5wPRdQD8AQiI82APT5EAxnDwJgUMAC8AXLES0M2JoSky5UPCorUN9ZkRLhoAZWCpKNNJqgADACQBvbQF8Xnf1AigsK8rOKWZLaoAEIAllQAknjy2O4eeACuALYARmi+urLyAB6qUXGJyfQAREzVLAEcQUIR0DAAhqgIEBVJwAA8ACpQEMXAEHgAJgiunjnxscm+AHz0w6PjUzNpiwBmaFB9I2MT01DzVIvAvvyHVap4EABuaK1qCLHAsS8A8o-0HS6PXifX6AHIAIxg5YhMQSUjQBztL6-f7YQHdXrJcEMKEwkRheFWd6fb4QUzozqYkHYsE4aGwwlvJEo8lOAFU4GVAZgpjQtjNRlQcRAA
π» Code
π Actual behavior
-0nis a valid and evalutates to0n, and"-0"matches`${bigint}`, but`${-0n}`evalutates to"0", and"-0"is not successfully inferred as0nπ Expected behavior
-0nshould either not exist, or it should be handled consistently with other bigint literals.Either:
-0nshould fail, and"-0"should not match`${bigint}`, because-0nis not a valid bigint value, and thus no such bigint stringifies to-0."-0"should be inferred to contain0n/-0n, because-0nis valid syntax that evalutates to0n.Additional information about the issue
Credit to mkantor and sinclair in the TypeScript Community for extra examples.