Skip to content

Commit acf6da7

Browse files
committed
Add slightly modified example from microsoft#25413
1 parent 9a71fbc commit acf6da7

5 files changed

+56
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13495,9 +13495,9 @@ namespace ts {
1349513495

1349613496
// TODO: Find a nice way to include potential conditional type breakdowns in error output, if those seems good (they usually don't)
1349713497
let localResult: Ternary | undefined;
13498-
if (skipTrue || (localResult = isRelatedTo(source, instantiateType(c.trueType, distributionMapper), /*reportErrors*/ false))) {
13498+
if (skipTrue || (localResult = isRelatedTo(source, instantiateType(getTrueTypeFromConditionalType(c), distributionMapper), /*reportErrors*/ false))) {
1349913499
if (!skipFalse) {
13500-
localResult = (localResult || Ternary.Maybe) & isRelatedTo(source, instantiateType(c.falseType, distributionMapper), /*reportErrors*/ false);
13500+
localResult = (localResult || Ternary.Maybe) & isRelatedTo(source, instantiateType(getFalseTypeFromConditionalType(c), distributionMapper), /*reportErrors*/ false);
1350113501
}
1350213502
}
1350313503
if (localResult) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [conditionalTypeSubclassExtendsTypeParam.ts]
2+
declare class Model<M extends MR, MR extends {}> {
3+
public getField2<K extends keyof M>(): Field<M[K], [K] extends [keyof MR] ? MR[K] : M[K]>
4+
}
5+
6+
declare class Field<T extends TR, TR> {
7+
}
8+
9+
//// [conditionalTypeSubclassExtendsTypeParam.js]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=== tests/cases/compiler/conditionalTypeSubclassExtendsTypeParam.ts ===
2+
declare class Model<M extends MR, MR extends {}> {
3+
>Model : Symbol(Model, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 0))
4+
>M : Symbol(M, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 20))
5+
>MR : Symbol(MR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 33))
6+
>MR : Symbol(MR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 33))
7+
8+
public getField2<K extends keyof M>(): Field<M[K], [K] extends [keyof MR] ? MR[K] : M[K]>
9+
>getField2 : Symbol(Model.getField2, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 50))
10+
>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21))
11+
>M : Symbol(M, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 20))
12+
>Field : Symbol(Field, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 2, 1))
13+
>M : Symbol(M, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 20))
14+
>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21))
15+
>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21))
16+
>MR : Symbol(MR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 33))
17+
>MR : Symbol(MR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 33))
18+
>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21))
19+
>M : Symbol(M, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 20))
20+
>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21))
21+
}
22+
23+
declare class Field<T extends TR, TR> {
24+
>Field : Symbol(Field, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 2, 1))
25+
>T : Symbol(T, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 4, 20))
26+
>TR : Symbol(TR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 4, 33))
27+
>TR : Symbol(TR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 4, 33))
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/conditionalTypeSubclassExtendsTypeParam.ts ===
2+
declare class Model<M extends MR, MR extends {}> {
3+
>Model : Model<M, MR>
4+
5+
public getField2<K extends keyof M>(): Field<M[K], [K] extends [keyof MR] ? MR[K] : M[K]>
6+
>getField2 : <K extends keyof M>() => Field<M[K], [K] extends [keyof MR] ? MR[K] : M[K]>
7+
}
8+
9+
declare class Field<T extends TR, TR> {
10+
>Field : Field<T, TR>
11+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare class Model<M extends MR, MR extends {}> {
2+
public getField2<K extends keyof M>(): Field<M[K], [K] extends [keyof MR] ? MR[K] : M[K]>
3+
}
4+
5+
declare class Field<T extends TR, TR> {
6+
}

0 commit comments

Comments
 (0)