mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Fixed an issue with generic naked T not being allowed as async generator's return (#49023)
This commit is contained in:
parent
a21024dbe7
commit
cd3bd5522b
@ -39273,9 +39273,14 @@ namespace ts {
|
||||
function unwrapReturnType(returnType: Type, functionFlags: FunctionFlags) {
|
||||
const isGenerator = !!(functionFlags & FunctionFlags.Generator);
|
||||
const isAsync = !!(functionFlags & FunctionFlags.Async);
|
||||
return isGenerator ? getIterationTypeOfGeneratorFunctionReturnType(IterationTypeKind.Return, returnType, isAsync) || errorType :
|
||||
isAsync ? getAwaitedTypeNoAlias(returnType) || errorType :
|
||||
returnType;
|
||||
if (isGenerator) {
|
||||
const returnIterationType = getIterationTypeOfGeneratorFunctionReturnType(IterationTypeKind.Return, returnType, isAsync);
|
||||
if (!returnIterationType) {
|
||||
return errorType;
|
||||
}
|
||||
return isAsync ? getAwaitedTypeNoAlias(unwrapAwaitedType(returnIterationType)) : returnIterationType;
|
||||
}
|
||||
return isAsync ? getAwaitedTypeNoAlias(returnType) || errorType : returnType;
|
||||
}
|
||||
|
||||
function isUnwrappedReturnTypeVoidOrAny(func: SignatureDeclaration, returnType: Type): boolean {
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
=== tests/cases/conformance/generators/asyncGeneratorGenericNonWrappedReturn.ts ===
|
||||
// #48966
|
||||
|
||||
export async function* test<T>(a: T): AsyncGenerator<T, T, T> {
|
||||
>test : Symbol(test, Decl(asyncGeneratorGenericNonWrappedReturn.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(asyncGeneratorGenericNonWrappedReturn.ts, 2, 28))
|
||||
>a : Symbol(a, Decl(asyncGeneratorGenericNonWrappedReturn.ts, 2, 31))
|
||||
>T : Symbol(T, Decl(asyncGeneratorGenericNonWrappedReturn.ts, 2, 28))
|
||||
>AsyncGenerator : Symbol(AsyncGenerator, Decl(lib.es2018.asyncgenerator.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(asyncGeneratorGenericNonWrappedReturn.ts, 2, 28))
|
||||
>T : Symbol(T, Decl(asyncGeneratorGenericNonWrappedReturn.ts, 2, 28))
|
||||
>T : Symbol(T, Decl(asyncGeneratorGenericNonWrappedReturn.ts, 2, 28))
|
||||
|
||||
return a // `T` should be allowed here even though the generator's `returnType` is `Awaited<T>`
|
||||
>a : Symbol(a, Decl(asyncGeneratorGenericNonWrappedReturn.ts, 2, 31))
|
||||
}
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
=== tests/cases/conformance/generators/asyncGeneratorGenericNonWrappedReturn.ts ===
|
||||
// #48966
|
||||
|
||||
export async function* test<T>(a: T): AsyncGenerator<T, T, T> {
|
||||
>test : <T>(a: T) => AsyncGenerator<T, T, T>
|
||||
>a : T
|
||||
|
||||
return a // `T` should be allowed here even though the generator's `returnType` is `Awaited<T>`
|
||||
>a : T
|
||||
}
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
// @target: esnext
|
||||
// @strict: true
|
||||
// @noEmit: true
|
||||
|
||||
// #48966
|
||||
|
||||
export async function* test<T>(a: T): AsyncGenerator<T, T, T> {
|
||||
return a // `T` should be allowed here even though the generator's `returnType` is `Awaited<T>`
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user