Skip to content

Commit f23dd7a

Browse files
authored
Fix crash in getAwaitedType (#52752)
1 parent 72fb827 commit f23dd7a

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39028,7 +39028,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3902839028
}
3902939029
}
3903039030

39031-
Debug.assert(getPromisedTypeOfPromise(type) === undefined, "type provided should not be a non-generic 'promise'-like.");
39031+
Debug.assert(isAwaitedTypeInstantiation(type) || getPromisedTypeOfPromise(type) === undefined, "type provided should not be a non-generic 'promise'-like.");
3903239032
return type;
3903339033
}
3903439034

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [awaitedTypeCrash.ts]
2+
// https://github.com/microsoft/TypeScript/issues/51984
3+
async function* f<T extends Promise<never>>(): AsyncGenerator<T, void, void> { }
4+
5+
//// [awaitedTypeCrash.js]
6+
// https://github.com/microsoft/TypeScript/issues/51984
7+
async function* f() { }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/awaitedTypeCrash.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/51984
3+
async function* f<T extends Promise<never>>(): AsyncGenerator<T, void, void> { }
4+
>f : Symbol(f, Decl(awaitedTypeCrash.ts, 0, 0))
5+
>T : Symbol(T, Decl(awaitedTypeCrash.ts, 1, 18))
6+
>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, --, --), Decl(lib.es2018.promise.d.ts, --, --))
7+
>AsyncGenerator : Symbol(AsyncGenerator, Decl(lib.es2018.asyncgenerator.d.ts, --, --))
8+
>T : Symbol(T, Decl(awaitedTypeCrash.ts, 1, 18))
9+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/compiler/awaitedTypeCrash.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/51984
3+
async function* f<T extends Promise<never>>(): AsyncGenerator<T, void, void> { }
4+
>f : <T extends Promise<never>>() => AsyncGenerator<T, void, void>
5+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @target: esnext
2+
3+
// https://github.com/microsoft/TypeScript/issues/51984
4+
async function* f<T extends Promise<never>>(): AsyncGenerator<T, void, void> { }

0 commit comments

Comments
 (0)