Add an extra test for contextually typed return of async function (#52613)

This commit is contained in:
Mateusz Burzyński 2023-03-08 00:30:40 +01:00 коммит произвёл GitHub
Родитель ff1e08f859
Коммит 2f229ab870
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 153 добавлений и 0 удалений

Просмотреть файл

@ -11,6 +11,25 @@ type MyCallback = (thing: string) => void;
declare function h(cb: (v: boolean) => MyCallback | PromiseLike<MyCallback>): 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;
};
});

Просмотреть файл

@ -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, --, --))
}
}

Просмотреть файл

@ -100,3 +100,56 @@ h(async v => v ? (def) => { } : Promise.reject());
>Promise : PromiseConstructor
>reject : <T = never>(reason?: any) => Promise<T>
// repro from #29196
const increment: (
>increment : (num: number, str: string) => string | Promise<string | ((s: string) => 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<string | ((s: string) => 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
}
}

Просмотреть файл

@ -12,3 +12,22 @@ type MyCallback = (thing: string) => void;
declare function h(cb: (v: boolean) => MyCallback | PromiseLike<MyCallback>): 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
}
}