-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRecent RegressionThis is a new regression just found in the last major/minor version of TypeScript.This is a new regression just found in the last major/minor version of TypeScript.
Description
π Search Terms
"conditional", "distributive", "distribution"
π Version & Regression Information
- This changed between versions 5.3 and 5.4
β― Playground Link
π» 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
muhammadk1607
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 issueRecent RegressionThis is a new regression just found in the last major/minor version of TypeScript.This is a new regression just found in the last major/minor version of TypeScript.