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

Regression in distributing on conditional types with T extends T after updating to 5.4 #57736

Closed
SuperKXT opened this issue Mar 12, 2024 · 2 comments Β· Fixed by #57751
Closed

Regression in distributing on conditional types with T extends T after updating to 5.4 #57736

SuperKXT opened this issue Mar 12, 2024 · 2 comments Β· Fixed by #57751
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Recent Regression This is a new regression just found in the last major/minor version of TypeScript.

Comments

@SuperKXT
Copy link

πŸ”Ž Search Terms

"conditional", "distributive", "distribution"

πŸ•— Version & Regression Information

  • This changed between versions 5.3 and 5.4

⏯ Playground Link

https://tsplay.dev/w1GDym

πŸ’» Code

type obj = {
  foo: 1;
  bar: 2;
};

type keyContaining1<
  str extends string,
  keys extends keyof obj = keyof obj,
> = keys extends infer key extends keyof obj
  ? key extends `${string}${str}${string}`
    ? obj[key]
    : never
  : never;

type _1 = keyContaining1<"foo">;
//   ^? type _1 = 4

type keyContaining2<
  str extends string,
  keys extends keyof obj = keyof obj,
> = keys extends keys
  ? keys extends `${string}${str}${string}`
    ? obj[keys]
    : never
  : never;

type _2 = keyContaining2<"foo">;
//   ^? type _1 = never

πŸ™ Actual behavior

The value of the generic param collapses to never when an additional conditional is added after the distributive conditional.
The error happens only when distributing with T extends T.
T extends any, T extends unknown, T extends infer U works fine.

πŸ™‚ Expected behavior

That the distributive type works similarly to the previous versions.

Additional information about the issue

No response

@RyanCavanaugh
Copy link
Member

Bisects to #56515

@ahejlsberg
Copy link
Member

I see what the issue is. I'll put up a PR shortly.

@ahejlsberg ahejlsberg added Bug A bug in TypeScript Recent Regression This is a new regression just found in the last major/minor version of TypeScript. Fix Available A PR has been opened for this issue labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Recent Regression This is a new regression just found in the last major/minor version of TypeScript.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants