From 2f229ab870c1436845d9a6b8915fd419b04c5756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 8 Mar 2023 00:30:40 +0100 Subject: [PATCH] Add an extra test for contextually typed return of async function (#52613) --- .../asyncFunctionContextuallyTypedReturns.js | 30 +++++++++++ ...ncFunctionContextuallyTypedReturns.symbols | 51 ++++++++++++++++++ ...syncFunctionContextuallyTypedReturns.types | 53 +++++++++++++++++++ .../asyncFunctionContextuallyTypedReturns.ts | 19 +++++++ 4 files changed, 153 insertions(+) diff --git a/tests/baselines/reference/asyncFunctionContextuallyTypedReturns.js b/tests/baselines/reference/asyncFunctionContextuallyTypedReturns.js index e06a4bde5e4..c35f947d4db 100644 --- a/tests/baselines/reference/asyncFunctionContextuallyTypedReturns.js +++ b/tests/baselines/reference/asyncFunctionContextuallyTypedReturns.js @@ -11,6 +11,25 @@ type MyCallback = (thing: string) => void; declare function h(cb: (v: boolean) => MyCallback | PromiseLike): void; h(v => v ? (abc) => { } : Promise.reject()); h(async v => v ? (def) => { } : Promise.reject()); + +// repro from #29196 +const increment: ( + num: number, + str: string +) => Promise<((s: string) => any) | string> | string = async (num, str) => { + return a => { + return a.length + } +} + +const increment2: ( + num: number, + str: string +) => Promise<((s: string) => any) | string> = async (num, str) => { + return a => { + return a.length + } +} //// [asyncFunctionContextuallyTypedReturns.js] @@ -30,3 +49,14 @@ g(v => v ? "contextuallyTypable" : Promise.reject()); g((v) => __awaiter(void 0, void 0, void 0, function* () { return v ? "contextuallyTypable" : Promise.reject(); })); h(v => v ? (abc) => { } : Promise.reject()); h((v) => __awaiter(void 0, void 0, void 0, function* () { return v ? (def) => { } : Promise.reject(); })); +// repro from #29196 +const increment = (num, str) => __awaiter(void 0, void 0, void 0, function* () { + return a => { + return a.length; + }; +}); +const increment2 = (num, str) => __awaiter(void 0, void 0, void 0, function* () { + return a => { + return a.length; + }; +}); diff --git a/tests/baselines/reference/asyncFunctionContextuallyTypedReturns.symbols b/tests/baselines/reference/asyncFunctionContextuallyTypedReturns.symbols index f3c5847e161..cad5a299077 100644 --- a/tests/baselines/reference/asyncFunctionContextuallyTypedReturns.symbols +++ b/tests/baselines/reference/asyncFunctionContextuallyTypedReturns.symbols @@ -73,3 +73,54 @@ h(async v => v ? (def) => { } : Promise.reject()); >Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >reject : Symbol(PromiseConstructor.reject, Decl(lib.es2015.promise.d.ts, --, --)) +// repro from #29196 +const increment: ( +>increment : Symbol(increment, Decl(asyncFunctionContextuallyTypedReturns.ts, 14, 5)) + + num: number, +>num : Symbol(num, Decl(asyncFunctionContextuallyTypedReturns.ts, 14, 18)) + + str: string +>str : Symbol(str, Decl(asyncFunctionContextuallyTypedReturns.ts, 15, 14)) + +) => Promise<((s: string) => any) | string> | string = async (num, str) => { +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>s : Symbol(s, Decl(asyncFunctionContextuallyTypedReturns.ts, 17, 15)) +>num : Symbol(num, Decl(asyncFunctionContextuallyTypedReturns.ts, 17, 62)) +>str : Symbol(str, Decl(asyncFunctionContextuallyTypedReturns.ts, 17, 66)) + + return a => { +>a : Symbol(a, Decl(asyncFunctionContextuallyTypedReturns.ts, 18, 8)) + + return a.length +>a.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>a : Symbol(a, Decl(asyncFunctionContextuallyTypedReturns.ts, 18, 8)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } +} + +const increment2: ( +>increment2 : Symbol(increment2, Decl(asyncFunctionContextuallyTypedReturns.ts, 23, 5)) + + num: number, +>num : Symbol(num, Decl(asyncFunctionContextuallyTypedReturns.ts, 23, 19)) + + str: string +>str : Symbol(str, Decl(asyncFunctionContextuallyTypedReturns.ts, 24, 14)) + +) => Promise<((s: string) => any) | string> = async (num, str) => { +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>s : Symbol(s, Decl(asyncFunctionContextuallyTypedReturns.ts, 26, 15)) +>num : Symbol(num, Decl(asyncFunctionContextuallyTypedReturns.ts, 26, 53)) +>str : Symbol(str, Decl(asyncFunctionContextuallyTypedReturns.ts, 26, 57)) + + return a => { +>a : Symbol(a, Decl(asyncFunctionContextuallyTypedReturns.ts, 27, 8)) + + return a.length +>a.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>a : Symbol(a, Decl(asyncFunctionContextuallyTypedReturns.ts, 27, 8)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } +} + diff --git a/tests/baselines/reference/asyncFunctionContextuallyTypedReturns.types b/tests/baselines/reference/asyncFunctionContextuallyTypedReturns.types index c349d687b9b..d639f34dcfb 100644 --- a/tests/baselines/reference/asyncFunctionContextuallyTypedReturns.types +++ b/tests/baselines/reference/asyncFunctionContextuallyTypedReturns.types @@ -100,3 +100,56 @@ h(async v => v ? (def) => { } : Promise.reject()); >Promise : PromiseConstructor >reject : (reason?: any) => Promise +// repro from #29196 +const increment: ( +>increment : (num: number, str: string) => string | Promise any)> + + num: number, +>num : number + + str: string +>str : string + +) => Promise<((s: string) => any) | string> | string = async (num, str) => { +>s : string +>async (num, str) => { return a => { return a.length }} : (num: number, str: string) => Promise<(a: string) => number> +>num : number +>str : string + + return a => { +>a => { return a.length } : (a: string) => number +>a : string + + return a.length +>a.length : number +>a : string +>length : number + } +} + +const increment2: ( +>increment2 : (num: number, str: string) => Promise any)> + + num: number, +>num : number + + str: string +>str : string + +) => Promise<((s: string) => any) | string> = async (num, str) => { +>s : string +>async (num, str) => { return a => { return a.length }} : (num: number, str: string) => Promise<(a: string) => number> +>num : number +>str : string + + return a => { +>a => { return a.length } : (a: string) => number +>a : string + + return a.length +>a.length : number +>a : string +>length : number + } +} + diff --git a/tests/cases/compiler/asyncFunctionContextuallyTypedReturns.ts b/tests/cases/compiler/asyncFunctionContextuallyTypedReturns.ts index f242b688afe..7bb3bfc7f99 100644 --- a/tests/cases/compiler/asyncFunctionContextuallyTypedReturns.ts +++ b/tests/cases/compiler/asyncFunctionContextuallyTypedReturns.ts @@ -12,3 +12,22 @@ type MyCallback = (thing: string) => void; declare function h(cb: (v: boolean) => MyCallback | PromiseLike): void; h(v => v ? (abc) => { } : Promise.reject()); h(async v => v ? (def) => { } : Promise.reject()); + +// repro from #29196 +const increment: ( + num: number, + str: string +) => Promise<((s: string) => any) | string> | string = async (num, str) => { + return a => { + return a.length + } +} + +const increment2: ( + num: number, + str: string +) => Promise<((s: string) => any) | string> = async (num, str) => { + return a => { + return a.length + } +}