-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
π Search Terms
invalid declaration distributive types
π Version & Regression Information
- This changed between versions 4.6 and 4.7
β― Playground Link
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
robpalme
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue