Ban inferred return type on async and generator functions. (#58628)

This commit is contained in:
Titian Cernicova-Dragomir
2024-05-23 19:29:49 +03:00
committed by GitHub
parent ddf43cd0e0
commit a203ace7af
5 changed files with 134 additions and 0 deletions

View File

@@ -14,10 +14,12 @@ import {
Expression,
forEachReturnStatement,
FunctionExpression,
FunctionFlags,
FunctionLikeDeclaration,
GetAccessorDeclaration,
getEffectiveReturnTypeNode,
getEffectiveTypeAnnotationNode,
getFunctionFlags,
getJSDocTypeAssertionType,
getStrictOptionValue,
HasInferredType,
@@ -469,6 +471,8 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve
function typeFromSingleReturnExpression(declaration: FunctionLikeDeclaration | undefined, context: SyntacticTypeNodeBuilderContext): boolean | undefined {
let candidateExpr: Expression | undefined;
if (declaration && !nodeIsMissing(declaration.body)) {
if (getFunctionFlags(declaration) & FunctionFlags.AsyncGenerator) return undefined;
const body = declaration.body;
if (body && isBlock(body)) {
forEachReturnStatement(body, s => {