From 044d70fc243e7f68214796611d8b93c0e31dec65 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 12 Jul 2019 17:57:05 -1000 Subject: [PATCH] Add regression tests --- .../compiler/instantiateContextualTypes.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/cases/compiler/instantiateContextualTypes.ts b/tests/cases/compiler/instantiateContextualTypes.ts index b81356fa91..3165011ecf 100644 --- a/tests/cases/compiler/instantiateContextualTypes.ts +++ b/tests/cases/compiler/instantiateContextualTypes.ts @@ -140,3 +140,37 @@ declare function passContentsToFunc(outerBox: T, consumer: BoxConsumerFromOut declare const outerBoxOfString: OuterBox; passContentsToFunc(outerBoxOfString, box => box.value); + +// Repro from #32349 + +type DooDad = 'SOMETHING' | 'ELSE' ; + +class Interesting { + public compiles = () : Promise => { + return Promise.resolve().then(() => { + if (1 < 2) { + return 'SOMETHING'; + } + return 'ELSE'; + }); + }; + public doesnt = () : Promise => { + return Promise.resolve().then(() => { + return 'ELSE'; + }); + }; + public slightlyDifferentErrorMessage = () : Promise => { + return Promise.resolve().then(() => { + if (1 < 2) { + return 'SOMETHING'; + } + return 'SOMETHING'; + }); + }; +} + +// Repro from #32349 + +declare function invoke(f: () => T): T; + +let xx: 0 | 1 | 2 = invoke(() => 1);