Mapped complex template keys=50
No-emit type-check timing for mapped complex template keys=50.
tsz is 6.1x faster 102 lines 3 KB
Timing
Files
// Mapped Type Complex Template Expansion O(N²) stress test
// Targets: evaluate_rules/mapped.rs — N properties × expensive template evaluation
//
// Unlike simple homomorphic mapped types ({ [K in keyof T]: T[K] }) where the
// template is trivial, these use conditional types and nested mapped types in
// the template position, making each property evaluation expensive.
// Utility types with non-trivial evaluation
type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T;
type Stringify<T> = { [K in keyof T]: T[K] extends number ? string : T[K] extends boolean ? 'true' | 'false' : T[K] extends string ? T[K] : string };
type Validate<T> = { [K in keyof T]: T[K] extends string ? { valid: true; value: T[K] } : T[K] extends number ? { valid: true; value: T[K] } : { valid: false; value: never } };
type Nullable<T> = { [K in keyof T]: T[K] | null | undefined };
type Promisify<T> = { [K in keyof T]: Promise<T[K]> };
// Complex conditional template: each property evaluation triggers conditional
// type distribution and nested type instantiation
type FormField<T> =
T extends string ? { type: 'text'; value: T; validate: (v: string) => boolean }
: T extends number ? { type: 'number'; value: T; validate: (v: number) => boolean }
: T extends boolean ? { type: 'checkbox'; value: T; validate: (v: boolean) => boolean }
: T extends (infer U)[] ? { type: 'list'; items: FormField<U>[]; validate: (v: U[]) => boolean }
: T extends object ? { type: 'group'; fields: FormFields<T>; validate: (v: T) => boolean }
: { type: 'unknown'; value: T };
type FormFields<T> = { [K in keyof T]: FormField<T[K]> };
interface BigModel {
field0: string;
field1: number;
field2: boolean;
field3: string[];
field4: { nested: string; count: number };
field5: string;
field6: number;
field7: boolean;
field8: string[];
field9: { nested: string; count: number };
field10: string;
field11: number;
field12: boolean;
field13: string[];
field14: { nested: string; count: number };
field15: string;
field16: number;
field17: boolean;
field18: string[];
field19: { nested: string; count: number };
field20: string;
field21: number;
field22: boolean;
field23: string[];
field24: { nested: string; count: number };
field25: string;
field26: number;
field27: boolean;
field28: string[];
field29: { nested: string; count: number };
field30: string;
field31: number;
field32: boolean;
field33: string[];
field34: { nested: string; count: number };
field35: string;
field36: number;
field37: boolean;
field38: string[];
field39: { nested: string; count: number };
field40: string;
field41: number;
field42: boolean;
field43: string[];
field44: { nested: string; count: number };
field45: string;
field46: number;
field47: boolean;
field48: string[];
field49: { nested: string; count: number };
}
// Each mapped type application evaluates a conditional template for 50 properties
type BigForm = FormFields<BigModel>;
type BigStringified = Stringify<BigModel>;
type BigValidated = Validate<BigModel>;
type BigNullable = Nullable<BigModel>;
type BigPromises = Promisify<BigModel>;
type BigDeepPartial = DeepPartial<BigModel>;
// Chained: each composition re-evaluates all 50 properties
type Chained1 = Nullable<Stringify<BigModel>>;
type Chained2 = Validate<Nullable<BigModel>>;
type Chained3 = FormFields<Nullable<BigModel>>;
declare const form: BigForm;
declare const stringified: BigStringified;
declare const validated: BigValidated;
declare const chained: Chained3;
const _f0 = form.field0;
const _s0 = stringified.field0;
const _v0 = validated.field0;
const _fLast = form.field49;
const _cLast = chained.field49;