Bug Report
π Search Terms
invalid declaration distributive types
π Version & Regression Information
- This changed between versions 4.6 and 4.7
β― Playground Link
Workbench
Playground Link For resulting declarations
π» Code
// @filename: types.ts
type Fns = Record<string, (...params: unknown[]) => unknown>
type Map<T extends Fns> = { [K in keyof T]: T[K]; };
type AllArg<T extends Fns> = { [K in keyof T]: Parameters<T[K]> };
function fn<T extends { x: Map<T['x']> }>(sliceIndex: T): AllArg<T['x']> {
return null!;
}
export default { fn };
// @filename: reexport.ts
import test from "./types";
export default { test };
π Actual behavior
TypeScript generates this declaration:
declare const _default: {
test: {
fn: <T_1 extends {
x: T_1["x"] extends infer T ? { [K in keyof T]: T_1["x"][K]; } : never;
}>(sliceIndex: T_1) => T_1["x"] extends infer T_2 ? { [K_1 in keyof T_2]: Parameters<T_1["x"][K_1]>; } : never;
};
};
export default _default;
In the declaration above the expression Parameters<T_1["x"][K_1]> doesn't type check. The T_1["x"] is not constrained anymore to be Record<string, (...params: unknown[]) => unknown>
TypeScript could include the constraint of the original type in the declaration:
declare const _default: {
test: {
fn: <T_1 extends {
x: T_1["x"] extends (infer T extends Record<string, (...params: unknown[]) => unknown>) ? { [K in keyof T]: T_1["x"][K]; } : never;
}>(sliceIndex: T_1) => T_1["x"] extends (infer T_2 extends Record<string, (...params: unknown[]) => unknown>)
? { [K_1 in keyof T_2]: Parameters<T_1["x"][K_1]>; } : never;
};
};
export default _default;
π Expected behavior
Resulting declarations for reexport.ts are valid
Bug Report
π Search Terms
invalid declaration distributive types
π Version & Regression Information
β― Playground Link
Workbench
Playground Link For resulting declarations
π» Code
π Actual behavior
TypeScript generates this declaration:
In the declaration above the expression
Parameters<T_1["x"][K_1]>doesn't type check. TheT_1["x"]is not constrained anymore to beRecord<string, (...params: unknown[]) => unknown>TypeScript could include the constraint of the original type in the declaration:
π Expected behavior
Resulting declarations for
reexport.tsare valid