Skip to content

Commit 0d494ab

Browse files
authored
Add missing unwrap call for the inferredExtendsType (#42409)
1 parent 147384c commit 0d494ab

5 files changed

+126
-1
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14613,7 +14613,7 @@ namespace ts {
1461314613
combinedMapper = mergeTypeMappers(mapper, context.mapper);
1461414614
}
1461514615
// Instantiate the extends type including inferences for 'infer T' type parameters
14616-
const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
14616+
const inferredExtendsType = combinedMapper ? instantiateType(unwrapNondistributiveConditionalTuple(root, root.extendsType), combinedMapper) : extendsType;
1461714617
// We attempt to resolve the conditional type only when the check and extends types are non-generic
1461814618
if (!checkTypeInstantiable && !isGenericObjectType(inferredExtendsType) && !isGenericIndexType(inferredExtendsType)) {
1461914619
// Return falseType for a definitely false extends check. We check an instantiations of the two
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [nondistributiveConditionalTypeInfer.ts]
2+
type _R<T> = [T] extends [{ _R: (_: infer R) => void }] ? R : never;
3+
type _E<T> = [T] extends [{ _E: () => infer E }] ? E : never;
4+
type _A<T> = [T] extends [{ _A: () => infer A }] ? A : never;
5+
6+
interface Sync<R, E, A> {
7+
_R: (_: R) => void;
8+
_E: () => E;
9+
_A: () => A;
10+
}
11+
12+
type R = _R<Sync<number, string, void>>;
13+
type E = _E<Sync<number, string, void>>;
14+
type A = _A<Sync<number, string, void>>;
15+
16+
//// [nondistributiveConditionalTypeInfer.js]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
=== tests/cases/compiler/nondistributiveConditionalTypeInfer.ts ===
2+
type _R<T> = [T] extends [{ _R: (_: infer R) => void }] ? R : never;
3+
>_R : Symbol(_R, Decl(nondistributiveConditionalTypeInfer.ts, 0, 0))
4+
>T : Symbol(T, Decl(nondistributiveConditionalTypeInfer.ts, 0, 8))
5+
>T : Symbol(T, Decl(nondistributiveConditionalTypeInfer.ts, 0, 8))
6+
>_R : Symbol(_R, Decl(nondistributiveConditionalTypeInfer.ts, 0, 27))
7+
>_ : Symbol(_, Decl(nondistributiveConditionalTypeInfer.ts, 0, 33))
8+
>R : Symbol(R, Decl(nondistributiveConditionalTypeInfer.ts, 0, 41))
9+
>R : Symbol(R, Decl(nondistributiveConditionalTypeInfer.ts, 0, 41))
10+
11+
type _E<T> = [T] extends [{ _E: () => infer E }] ? E : never;
12+
>_E : Symbol(_E, Decl(nondistributiveConditionalTypeInfer.ts, 0, 68))
13+
>T : Symbol(T, Decl(nondistributiveConditionalTypeInfer.ts, 1, 8))
14+
>T : Symbol(T, Decl(nondistributiveConditionalTypeInfer.ts, 1, 8))
15+
>_E : Symbol(_E, Decl(nondistributiveConditionalTypeInfer.ts, 1, 27))
16+
>E : Symbol(E, Decl(nondistributiveConditionalTypeInfer.ts, 1, 43))
17+
>E : Symbol(E, Decl(nondistributiveConditionalTypeInfer.ts, 1, 43))
18+
19+
type _A<T> = [T] extends [{ _A: () => infer A }] ? A : never;
20+
>_A : Symbol(_A, Decl(nondistributiveConditionalTypeInfer.ts, 1, 61))
21+
>T : Symbol(T, Decl(nondistributiveConditionalTypeInfer.ts, 2, 8))
22+
>T : Symbol(T, Decl(nondistributiveConditionalTypeInfer.ts, 2, 8))
23+
>_A : Symbol(_A, Decl(nondistributiveConditionalTypeInfer.ts, 2, 27))
24+
>A : Symbol(A, Decl(nondistributiveConditionalTypeInfer.ts, 2, 43))
25+
>A : Symbol(A, Decl(nondistributiveConditionalTypeInfer.ts, 2, 43))
26+
27+
interface Sync<R, E, A> {
28+
>Sync : Symbol(Sync, Decl(nondistributiveConditionalTypeInfer.ts, 2, 61))
29+
>R : Symbol(R, Decl(nondistributiveConditionalTypeInfer.ts, 4, 15))
30+
>E : Symbol(E, Decl(nondistributiveConditionalTypeInfer.ts, 4, 17))
31+
>A : Symbol(A, Decl(nondistributiveConditionalTypeInfer.ts, 4, 20))
32+
33+
_R: (_: R) => void;
34+
>_R : Symbol(Sync._R, Decl(nondistributiveConditionalTypeInfer.ts, 4, 25))
35+
>_ : Symbol(_, Decl(nondistributiveConditionalTypeInfer.ts, 5, 7))
36+
>R : Symbol(R, Decl(nondistributiveConditionalTypeInfer.ts, 4, 15))
37+
38+
_E: () => E;
39+
>_E : Symbol(Sync._E, Decl(nondistributiveConditionalTypeInfer.ts, 5, 21))
40+
>E : Symbol(E, Decl(nondistributiveConditionalTypeInfer.ts, 4, 17))
41+
42+
_A: () => A;
43+
>_A : Symbol(Sync._A, Decl(nondistributiveConditionalTypeInfer.ts, 6, 14))
44+
>A : Symbol(A, Decl(nondistributiveConditionalTypeInfer.ts, 4, 20))
45+
}
46+
47+
type R = _R<Sync<number, string, void>>;
48+
>R : Symbol(R, Decl(nondistributiveConditionalTypeInfer.ts, 8, 1))
49+
>_R : Symbol(_R, Decl(nondistributiveConditionalTypeInfer.ts, 0, 0))
50+
>Sync : Symbol(Sync, Decl(nondistributiveConditionalTypeInfer.ts, 2, 61))
51+
52+
type E = _E<Sync<number, string, void>>;
53+
>E : Symbol(E, Decl(nondistributiveConditionalTypeInfer.ts, 10, 40))
54+
>_E : Symbol(_E, Decl(nondistributiveConditionalTypeInfer.ts, 0, 68))
55+
>Sync : Symbol(Sync, Decl(nondistributiveConditionalTypeInfer.ts, 2, 61))
56+
57+
type A = _A<Sync<number, string, void>>;
58+
>A : Symbol(A, Decl(nondistributiveConditionalTypeInfer.ts, 11, 40))
59+
>_A : Symbol(_A, Decl(nondistributiveConditionalTypeInfer.ts, 1, 61))
60+
>Sync : Symbol(Sync, Decl(nondistributiveConditionalTypeInfer.ts, 2, 61))
61+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=== tests/cases/compiler/nondistributiveConditionalTypeInfer.ts ===
2+
type _R<T> = [T] extends [{ _R: (_: infer R) => void }] ? R : never;
3+
>_R : _R<T>
4+
>_R : (_: infer R) => void
5+
>_ : R
6+
7+
type _E<T> = [T] extends [{ _E: () => infer E }] ? E : never;
8+
>_E : _E<T>
9+
>_E : () => infer E
10+
11+
type _A<T> = [T] extends [{ _A: () => infer A }] ? A : never;
12+
>_A : _A<T>
13+
>_A : () => infer A
14+
15+
interface Sync<R, E, A> {
16+
_R: (_: R) => void;
17+
>_R : (_: R) => void
18+
>_ : R
19+
20+
_E: () => E;
21+
>_E : () => E
22+
23+
_A: () => A;
24+
>_A : () => A
25+
}
26+
27+
type R = _R<Sync<number, string, void>>;
28+
>R : number
29+
30+
type E = _E<Sync<number, string, void>>;
31+
>E : string
32+
33+
type A = _A<Sync<number, string, void>>;
34+
>A : void
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
type _R<T> = [T] extends [{ _R: (_: infer R) => void }] ? R : never;
2+
type _E<T> = [T] extends [{ _E: () => infer E }] ? E : never;
3+
type _A<T> = [T] extends [{ _A: () => infer A }] ? A : never;
4+
5+
interface Sync<R, E, A> {
6+
_R: (_: R) => void;
7+
_E: () => E;
8+
_A: () => A;
9+
}
10+
11+
type R = _R<Sync<number, string, void>>;
12+
type E = _E<Sync<number, string, void>>;
13+
type A = _A<Sync<number, string, void>>;

0 commit comments

Comments
 (0)