Closed
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