Closed
Description
π Version & Regression Information
All versions.
β― Playground Link
Playground link with relevant code
π» Code
type Digits = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
type T9XXXX = `9${Digits}${Digits}${Digits}${Digits}`;
type TXXXXX = `${Exclude<Digits, '0'>}${Digits}${Digits}${Digits}${Digits}`;
let x: Exclude<TXXXXX, T9XXXX> = '88888';
π Actual behavior
The example above takes ~45s to compile on a reasonably fast machine. The underlying issue is that as we relate large unions of primitive types, we have a fast path for matches, but not for mismatches. Because the majority of the constituents of TXXXXX
are not present in T9XXXX
, we spend a lot of time in the slow path that attempts to find matches by iterating through all constituents.
π Expected behavior
We can do much better by implementing a fast path for mismatches.
Activity
fatcerberus commentedon Mar 10, 2023
So more out of morbid curiosity than anything...
That was with an M2 Pro. Holy crap.