Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inferring less information for generics in 4.2+ compared to previous versions #45471

Open
Haroenv opened this issue Aug 16, 2021 · 0 comments
Open
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@Haroenv
Copy link

Haroenv commented Aug 16, 2021

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?

#43161
#42939

🕗 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.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Aug 17, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.5.0 milestone Aug 17, 2021
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

No branches or pull requests

3 participants