Skip to content

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

Closed
@SuperKXT

Description

@SuperKXT

πŸ”Ž 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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRecent RegressionThis is a new regression just found in the last major/minor version of TypeScript.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions