Infer stress N=15
No-emit type-check timing for infer stress n=15.
tsz is 5.4x faster 249 lines 5 KB
Timing
Files
// Infer keyword stress test
// Tests inference variable resolution in conditional types
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
type UnwrapArray<T> = T extends (infer U)[] ? U : T;
type MyParameters<T> = T extends (...args: infer P) => any ? P : never;
type MyReturnType<T> = T extends (...args: any[]) => infer R ? R : never;
// Multi-infer conditional
type FirstAndRest<T> = T extends [infer First, ...infer Rest] ? { first: First; rest: Rest } : never;
// Nested infer
type DeepUnwrap<T> =
T extends Promise<infer U> ? DeepUnwrap<U> :
T extends (infer V)[] ? DeepUnwrap<V>[] :
T;
// Infer in template literal
type ExtractPrefix<T> = T extends `${infer P}_${string}` ? P : never;
// Infer with constraints
type ExtractIfString<T> = T extends infer U extends string ? U : never;
declare function func0(
arg0: string
): number;
type Params0 = MyParameters<typeof func0>;
type Return0 = MyReturnType<typeof func0>;
declare function func1(
arg0: string,
arg1: string
): number;
type Params1 = MyParameters<typeof func1>;
type Return1 = MyReturnType<typeof func1>;
declare function func2(
arg0: string,
arg1: string,
arg2: string
): number;
type Params2 = MyParameters<typeof func2>;
type Return2 = MyReturnType<typeof func2>;
declare function func3(
arg0: string,
arg1: string,
arg2: string,
arg3: string
): number;
type Params3 = MyParameters<typeof func3>;
type Return3 = MyReturnType<typeof func3>;
declare function func4(
arg0: string,
arg1: string,
arg2: string,
arg3: string,
arg4: string
): number;
type Params4 = MyParameters<typeof func4>;
type Return4 = MyReturnType<typeof func4>;
declare function func5(
arg0: string,
arg1: string,
arg2: string,
arg3: string,
arg4: string,
arg5: string
): number;
type Params5 = MyParameters<typeof func5>;
type Return5 = MyReturnType<typeof func5>;
declare function func6(
arg0: string,
arg1: string,
arg2: string,
arg3: string,
arg4: string,
arg5: string,
arg6: string
): number;
type Params6 = MyParameters<typeof func6>;
type Return6 = MyReturnType<typeof func6>;
declare function func7(
arg0: string,
arg1: string,
arg2: string,
arg3: string,
arg4: string,
arg5: string,
arg6: string,
arg7: string
): number;
type Params7 = MyParameters<typeof func7>;
type Return7 = MyReturnType<typeof func7>;
declare function func8(
arg0: string,
arg1: string,
arg2: string,
arg3: string,
arg4: string,
arg5: string,
arg6: string,
arg7: string,
arg8: string
): number;
type Params8 = MyParameters<typeof func8>;
type Return8 = MyReturnType<typeof func8>;
declare function func9(
arg0: string,
arg1: string,
arg2: string,
arg3: string,
arg4: string,
arg5: string,
arg6: string,
arg7: string,
arg8: string,
arg9: string
): number;
type Params9 = MyParameters<typeof func9>;
type Return9 = MyReturnType<typeof func9>;
declare function func10(
arg0: string,
arg1: string,
arg2: string,
arg3: string,
arg4: string,
arg5: string,
arg6: string,
arg7: string,
arg8: string,
arg9: string,
arg10: string
): number;
type Params10 = MyParameters<typeof func10>;
type Return10 = MyReturnType<typeof func10>;
declare function func11(
arg0: string,
arg1: string,
arg2: string,
arg3: string,
arg4: string,
arg5: string,
arg6: string,
arg7: string,
arg8: string,
arg9: string,
arg10: string,
arg11: string
): number;
type Params11 = MyParameters<typeof func11>;
type Return11 = MyReturnType<typeof func11>;
declare function func12(
arg0: string,
arg1: string,
arg2: string,
arg3: string,
arg4: string,
arg5: string,
arg6: string,
arg7: string,
arg8: string,
arg9: string,
arg10: string,
arg11: string,
arg12: string
): number;
type Params12 = MyParameters<typeof func12>;
type Return12 = MyReturnType<typeof func12>;
declare function func13(
arg0: string,
arg1: string,
arg2: string,
arg3: string,
arg4: string,
arg5: string,
arg6: string,
arg7: string,
arg8: string,
arg9: string,
arg10: string,
arg11: string,
arg12: string,
arg13: string
): number;
type Params13 = MyParameters<typeof func13>;
type Return13 = MyReturnType<typeof func13>;
declare function func14(
arg0: string,
arg1: string,
arg2: string,
arg3: string,
arg4: string,
arg5: string,
arg6: string,
arg7: string,
arg8: string,
arg9: string,
arg10: string,
arg11: string,
arg12: string,
arg13: string,
arg14: string
): number;
type Params14 = MyParameters<typeof func14>;
type Return14 = MyReturnType<typeof func14>;
// Complex nested inference
type ComplexInfer<T> = T extends {
data: infer D;
nested: { value: infer V }[]
} ? { data: D; values: V[] } : never;
interface TestData {
data: string;
nested: { value: number }[];
}
type Inferred = ComplexInfer<TestData>;
declare const params: Params14;
declare const inferred: Inferred;