|
| 1 | +import {expectType} from 'tsd'; |
| 2 | +import type {Absolute} from '../source/absolute.d.ts'; |
| 3 | +import type {NegativeInfinity, PositiveInfinity} from '../source/numeric.d.ts'; |
| 4 | + |
| 5 | +// Integers |
| 6 | +expectType<Absolute<0>>(0); |
| 7 | +expectType<Absolute<1>>(1); |
| 8 | +expectType<Absolute<-1>>(1); |
| 9 | +expectType<Absolute<100>>(100); |
| 10 | +expectType<Absolute<-100>>(100); |
| 11 | + |
| 12 | +// Bigints |
| 13 | +expectType<Absolute<0n>>(0n); |
| 14 | +expectType<Absolute<512n>>(512n); |
| 15 | +expectType<Absolute<-512n>>(512n); |
| 16 | +expectType<Absolute<9_999_999_999_999_999n>>(9_999_999_999_999_999n); |
| 17 | +expectType<Absolute<-9_999_999_999_999_999n>>(9_999_999_999_999_999n); |
| 18 | + |
| 19 | +// Infinity |
| 20 | +expectType<Absolute<PositiveInfinity>>({} as PositiveInfinity); |
| 21 | +expectType<Absolute<NegativeInfinity>>({} as PositiveInfinity); |
| 22 | + |
| 23 | +// Decimals |
| 24 | +expectType<Absolute<3.1428>>(3.1428); |
| 25 | +expectType<Absolute<-3.1428>>(3.1428); |
| 26 | +expectType<Absolute<0.5>>(0.5); |
| 27 | +expectType<Absolute<-0.5>>(0.5); |
| 28 | + |
| 29 | +// Numeric separators |
| 30 | +expectType<Absolute<1_000_000>>(1_000_000); |
| 31 | +expectType<Absolute<-1_000_000>>(1_000_000); |
| 32 | +expectType<Absolute<1_000_000n>>(1_000_000n); |
| 33 | +expectType<Absolute<-1_000_000n>>(1_000_000n); |
| 34 | + |
| 35 | +// Binaries |
| 36 | +expectType<Absolute<0b10>>(0b10); |
| 37 | +expectType<Absolute<-0b10>>(0b10); |
| 38 | +expectType<Absolute<0b11_1000n>>(0b11_1000n); |
| 39 | +expectType<Absolute<-0b11_1000n>>(0b11_1000n); |
| 40 | + |
| 41 | +// Octals |
| 42 | +expectType<Absolute<0o70>>(0o70); |
| 43 | +expectType<Absolute<-0o70>>(0o70); |
| 44 | +expectType<Absolute<0o77_7000n>>(0o77_7000n); |
| 45 | +expectType<Absolute<-0o77_7000n>>(0o77_7000n); |
| 46 | + |
| 47 | +// Hexadecimals |
| 48 | +expectType<Absolute<0xF0>>(0xF0); |
| 49 | +expectType<Absolute<-0xF0>>(0xF0); |
| 50 | +expectType<Absolute<0xFF_F0_00n>>(0xFF_F0_00n); |
| 51 | +expectType<Absolute<-0xFF_F0_00n>>(0xFF_F0_00n); |
| 52 | + |
| 53 | +// Scientific notations |
| 54 | +expectType<Absolute<6.022e23>>(6.022e23); |
| 55 | +expectType<Absolute<-6.022e23>>(6.022e23); |
| 56 | +expectType<Absolute<6.626e-34>>(6.626e-34); |
| 57 | +expectType<Absolute<-6.626e-34>>(6.626e-34); |
| 58 | +expectType<Absolute<3e8>>(3e8); |
| 59 | +expectType<Absolute<-1.2345e2>>(1.2345e2); |
| 60 | + |
| 61 | +// Non literals |
| 62 | +expectType<number>({} as Absolute<number>); |
| 63 | +expectType<bigint>({} as Absolute<bigint>); |
| 64 | +expectType<number | bigint>({} as Absolute<number | bigint>); |
| 65 | + |
| 66 | +// Unions |
| 67 | +// 1. Literal members |
| 68 | +expectType<Absolute<0 | 1 | 2>>({} as 0 | 1 | 2); |
| 69 | +expectType<Absolute<2 | 4 | 8 | 16>>({} as 2 | 4 | 8 | 16); |
| 70 | +expectType<Absolute<-98_765n | -12_345n>>({} as 98_765n | 12_345n); |
| 71 | +expectType<Absolute<-2 | -1 | 0>>({} as 2 | 1 | 0); |
| 72 | +expectType<Absolute<2 | -2>>(2); |
| 73 | +expectType<Absolute<-12_345n | 12_345n>>(12_345n); |
| 74 | +expectType<Absolute<2 | 4 | -12_345n>>({} as 2 | 4 | 12_345n); |
| 75 | +expectType<Absolute<2 | 98_765n | 9.8 | 0b11n | 0o77 | 0xFF | 3e8>>({} as 2 | 98_765n | 9.8 | 0b11n | 0o77 | 0xFF | 3e8); |
| 76 | +expectType<Absolute<-2 | -98_765n | -9.8 | -0b11n | -0o77 | -0xFF | -3e8>>({} as 2 | 98_765n | 9.8 | 0b11n | 0o77 | 0xFF | 3e8); |
| 77 | +expectType<Absolute<-2 | -98_765n | 9.8 | 0b11n | 0o77 | -0xFF | 3e8>>({} as 2 | 98_765n | 9.8 | 0b11n | 0o77 | 0xFF | 3e8); |
| 78 | + |
| 79 | +// 2. Literal and non-literal members |
| 80 | +expectType<Absolute<bigint | 100>>({} as bigint | 100); |
| 81 | +expectType<Absolute<bigint | -100>>({} as bigint | 100); |
| 82 | +expectType<Absolute<123_456_789n | number>>({} as 123_456_789n | number); |
| 83 | +expectType<Absolute<-123_456_789n | number>>({} as 123_456_789n | number); |
| 84 | + |
| 85 | +// Boundary cases |
| 86 | +expectType<any>({} as Absolute<any>); |
| 87 | +expectType<never>({} as Absolute<never>); |
0 commit comments