From acf6da7a722ac3dc870a011ec01a404093df397d Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 13 Aug 2019 15:37:58 -0700 Subject: [PATCH] Add slightly modified example from #25413 --- src/compiler/checker.ts | 4 +-- ...conditionalTypeSubclassExtendsTypeParam.js | 9 ++++++ ...tionalTypeSubclassExtendsTypeParam.symbols | 28 +++++++++++++++++++ ...ditionalTypeSubclassExtendsTypeParam.types | 11 ++++++++ ...conditionalTypeSubclassExtendsTypeParam.ts | 6 ++++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/conditionalTypeSubclassExtendsTypeParam.js create mode 100644 tests/baselines/reference/conditionalTypeSubclassExtendsTypeParam.symbols create mode 100644 tests/baselines/reference/conditionalTypeSubclassExtendsTypeParam.types create mode 100644 tests/cases/compiler/conditionalTypeSubclassExtendsTypeParam.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ebda82615bfc5..ee640ec2d7211 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13495,9 +13495,9 @@ namespace ts { // TODO: Find a nice way to include potential conditional type breakdowns in error output, if those seems good (they usually don't) let localResult: Ternary | undefined; - if (skipTrue || (localResult = isRelatedTo(source, instantiateType(c.trueType, distributionMapper), /*reportErrors*/ false))) { + if (skipTrue || (localResult = isRelatedTo(source, instantiateType(getTrueTypeFromConditionalType(c), distributionMapper), /*reportErrors*/ false))) { if (!skipFalse) { - localResult = (localResult || Ternary.Maybe) & isRelatedTo(source, instantiateType(c.falseType, distributionMapper), /*reportErrors*/ false); + localResult = (localResult || Ternary.Maybe) & isRelatedTo(source, instantiateType(getFalseTypeFromConditionalType(c), distributionMapper), /*reportErrors*/ false); } } if (localResult) { diff --git a/tests/baselines/reference/conditionalTypeSubclassExtendsTypeParam.js b/tests/baselines/reference/conditionalTypeSubclassExtendsTypeParam.js new file mode 100644 index 0000000000000..e2334e631b206 --- /dev/null +++ b/tests/baselines/reference/conditionalTypeSubclassExtendsTypeParam.js @@ -0,0 +1,9 @@ +//// [conditionalTypeSubclassExtendsTypeParam.ts] +declare class Model { + public getField2(): Field +} + +declare class Field { +} + +//// [conditionalTypeSubclassExtendsTypeParam.js] diff --git a/tests/baselines/reference/conditionalTypeSubclassExtendsTypeParam.symbols b/tests/baselines/reference/conditionalTypeSubclassExtendsTypeParam.symbols new file mode 100644 index 0000000000000..a2c25631171dd --- /dev/null +++ b/tests/baselines/reference/conditionalTypeSubclassExtendsTypeParam.symbols @@ -0,0 +1,28 @@ +=== tests/cases/compiler/conditionalTypeSubclassExtendsTypeParam.ts === +declare class Model { +>Model : Symbol(Model, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 0)) +>M : Symbol(M, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 20)) +>MR : Symbol(MR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 33)) +>MR : Symbol(MR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 33)) + + public getField2(): Field +>getField2 : Symbol(Model.getField2, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 50)) +>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21)) +>M : Symbol(M, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 20)) +>Field : Symbol(Field, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 2, 1)) +>M : Symbol(M, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 20)) +>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21)) +>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21)) +>MR : Symbol(MR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 33)) +>MR : Symbol(MR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 33)) +>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21)) +>M : Symbol(M, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 0, 20)) +>K : Symbol(K, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 1, 21)) +} + +declare class Field { +>Field : Symbol(Field, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 2, 1)) +>T : Symbol(T, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 4, 20)) +>TR : Symbol(TR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 4, 33)) +>TR : Symbol(TR, Decl(conditionalTypeSubclassExtendsTypeParam.ts, 4, 33)) +} diff --git a/tests/baselines/reference/conditionalTypeSubclassExtendsTypeParam.types b/tests/baselines/reference/conditionalTypeSubclassExtendsTypeParam.types new file mode 100644 index 0000000000000..63a3834c2a364 --- /dev/null +++ b/tests/baselines/reference/conditionalTypeSubclassExtendsTypeParam.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/conditionalTypeSubclassExtendsTypeParam.ts === +declare class Model { +>Model : Model + + public getField2(): Field +>getField2 : () => Field +} + +declare class Field { +>Field : Field +} diff --git a/tests/cases/compiler/conditionalTypeSubclassExtendsTypeParam.ts b/tests/cases/compiler/conditionalTypeSubclassExtendsTypeParam.ts new file mode 100644 index 0000000000000..31bd6c6b81818 --- /dev/null +++ b/tests/cases/compiler/conditionalTypeSubclassExtendsTypeParam.ts @@ -0,0 +1,6 @@ +declare class Model { + public getField2(): Field +} + +declare class Field { +} \ No newline at end of file