-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
Bug Report
infer used as the value of a generic no longer infers the actual value, but it infers the default value of that generic argument.
🔎 Search Terms
infer, unknown, default, generic
possibly similar issues?
🕗 Version & Regression Information
- This changed between versions 4.1.5 and 4.2.3
⏯ Playground Link
Playground link with relevant code in 4.2.3
Playground link with relevant code in 4.1.5
💻 Code
type Shape = {
key: Record<string, unknown>;
};
type ShapeCreator<T extends Shape> = (cb: (state: T['key']) => void) => void;
type ExtractShape<T> = T extends ShapeCreator<infer TShape> ? TShape : never;
type StateShape = {
key: { letter: string };
};
type StateShapeCreator = ShapeCreator<StateShape>;
const wrongShape: ExtractShape<StateShapeCreator> = {
key: {
// @ts-expect-error
letter: 2,
},
};
🙁 Actual behavior
the inferred value is the default of the generic
🙂 Expected behavior
the inferred value is the actual value of the generic, like it used to do.
tkrugg, bartlomiej-korpus and psd-coder
Metadata
Metadata
Assignees
Labels
Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone