Template literal N=20

No-emit type-check timing for template literal n=20.

tsz is 5.5x faster 83 lines 1 KB

Timing

tsz
71.90ms
tsgo
392.09ms

Files

// Template literal type expansion stress test
// Tests Cartesian product explosion prevention

type Colors =
    | 'color0'
    | 'color1'
    | 'color2'
    | 'color3'
    | 'color4'
    | 'color5'
    | 'color6'
    | 'color7'
    | 'color8'
    | 'color9'
    | 'color10'
    | 'color11'
    | 'color12'
    | 'color13'
    | 'color14'
    | 'color15'
    | 'color16'
    | 'color17'
    | 'color18'
    | 'color19';

type Sizes =
    | 'size0'
    | 'size1'
    | 'size2'
    | 'size3'
    | 'size4'
    | 'size5'
    | 'size6'
    | 'size7'
    | 'size8'
    | 'size9'
    | 'size10'
    | 'size11'
    | 'size12'
    | 'size13'
    | 'size14'
    | 'size15'
    | 'size16'
    | 'size17'
    | 'size18'
    | 'size19';

type Variants =
    | 'variant0'
    | 'variant1'
    | 'variant2'
    | 'variant3'
    | 'variant4'
    | 'variant5'
    | 'variant6'
    | 'variant7'
    | 'variant8'
    | 'variant9'
    | 'variant10'
    | 'variant11'
    | 'variant12'
    | 'variant13'
    | 'variant14'
    | 'variant15'
    | 'variant16'
    | 'variant17'
    | 'variant18'
    | 'variant19';

// Template literal Cartesian products
type ProductSmall = `${Colors}-${Sizes}`;
type ProductMedium = `${Colors}-${Sizes}-${Variants}`;

// String manipulation types
type Prefixed = `prefix_${Colors}`;
type Suffixed = `${Colors}_suffix`;
type Wrapped = `[${Colors}]`;

// Nested template
type NestedTemplate = `start_${`mid_${Colors}`}_end`;

declare const product: ProductSmall;
declare const prefixed: Prefixed;