Type Alias ToNegative<N>

ToNegative: N extends number
    ? N extends 0 ? 0 : `-${N}` extends `${infer W extends number}` ? W : N
    : N extends 0n ? 0n : `-${N}` extends `${infer W extends bigint}` ? W : N

Converts a number or bigint N to negative. If N is already negative, it returns itself.

Type Parameters

  • N extends number | bigint
ToNegative<5> // -5
ToNegative<0> // 0
ToNegative<-5> // -5