@@ -8031,7 +8031,7 @@ namespace ts {
80318031 function getLiteralTypeFromPropertyName(prop: Symbol) {
80328032 const links = getSymbolLinks(getLateBoundSymbol(prop));
80338033 if (!links.nameType) {
8034- if (links.target) {
8034+ if (links.target && links.target !== unknownSymbol && links.target !== resolvingSymbol ) {
80358035 Debug.assert(links.target.escapedName === prop.escapedName || links.target.escapedName === InternalSymbolName.Computed, "Target symbol and symbol do not have the same name");
80368036 links.nameType = getLiteralTypeFromPropertyName(links.target);
80378037 }
@@ -14115,7 +14115,7 @@ namespace ts {
1411514115 }
1411614116 }
1411714117
14118- function getContainingObjectLiteral(func: FunctionLike ): ObjectLiteralExpression | undefined {
14118+ function getContainingObjectLiteral(func: SignatureDeclaration ): ObjectLiteralExpression | undefined {
1411914119 return (func.kind === SyntaxKind.MethodDeclaration ||
1412014120 func.kind === SyntaxKind.GetAccessor ||
1412114121 func.kind === SyntaxKind.SetAccessor) && func.parent.kind === SyntaxKind.ObjectLiteralExpression ? func.parent :
@@ -14133,7 +14133,7 @@ namespace ts {
1413314133 });
1413414134 }
1413514135
14136- function getContextualThisParameterType(func: FunctionLike ): Type {
14136+ function getContextualThisParameterType(func: SignatureDeclaration ): Type {
1413714137 if (func.kind === SyntaxKind.ArrowFunction) {
1413814138 return undefined;
1413914139 }
@@ -14330,7 +14330,7 @@ namespace ts {
1433014330 return false;
1433114331 }
1433214332
14333- function getContextualReturnType(functionDecl: FunctionLike ): Type {
14333+ function getContextualReturnType(functionDecl: SignatureDeclaration ): Type {
1433414334 // If the containing function has a return type annotation, is a constructor, or is a get accessor whose
1433514335 // corresponding set accessor has a type annotation, return statements in the function are contextually typed
1433614336 if (functionDecl.kind === SyntaxKind.Constructor ||
@@ -18528,27 +18528,23 @@ namespace ts {
1852818528
1852918529 function checkAndAggregateYieldOperandTypes(func: FunctionLikeDeclaration, checkMode: CheckMode): Type[] {
1853018530 const aggregatedTypes: Type[] = [];
18531- const functionFlags = getFunctionFlags(func);
18531+ const isAsync = ( getFunctionFlags(func) & FunctionFlags.Async) !== 0 ;
1853218532 forEachYieldExpression(<Block>func.body, yieldExpression => {
18533- const expr = yieldExpression.expression;
18534- if (expr) {
18535- let type = checkExpressionCached(expr, checkMode);
18536- if (yieldExpression.asteriskToken) {
18537- // A yield* expression effectively yields everything that its operand yields
18538- type = checkIteratedTypeOrElementType(type, yieldExpression.expression, /*allowStringInput*/ false, (functionFlags & FunctionFlags.Async) !== 0);
18539- }
18540- if (functionFlags & FunctionFlags.Async) {
18541- type = checkAwaitedType(type, expr, yieldExpression.asteriskToken
18542- ? Diagnostics.Type_of_iterated_elements_of_a_yield_Asterisk_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
18543- : Diagnostics.Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member);
18544- }
18545- pushIfUnique(aggregatedTypes, type);
18546- }
18533+ pushIfUnique(aggregatedTypes, getYieldedTypeOfYieldExpression(yieldExpression, isAsync, checkMode));
1854718534 });
18548-
1854918535 return aggregatedTypes;
1855018536 }
1855118537
18538+ function getYieldedTypeOfYieldExpression(node: YieldExpression, isAsync: boolean, checkMode?: CheckMode): Type {
18539+ const errorNode = node.expression || node;
18540+ const expressionType = node.expression ? checkExpressionCached(node.expression, checkMode) : undefinedWideningType;
18541+ // A `yield*` expression effectively yields everything that its operand yields
18542+ const yieldedType = node.asteriskToken ? checkIteratedTypeOrElementType(expressionType, errorNode, /*allowStringInput*/ false, isAsync) : expressionType;
18543+ return !isAsync ? yieldedType : getAwaitedType(yieldedType, errorNode, node.asteriskToken
18544+ ? Diagnostics.Type_of_iterated_elements_of_a_yield_Asterisk_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
18545+ : Diagnostics.Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member);
18546+ }
18547+
1855218548 function isExhaustiveSwitchStatement(node: SwitchStatement): boolean {
1855318549 if (!node.possiblyExhaustive) {
1855418550 return false;
@@ -19504,62 +19500,40 @@ namespace ts {
1950419500 }
1950519501 }
1950619502
19507- if (node.expression) {
19508- const func = getContainingFunction(node);
19509- // If the user's code is syntactically correct, the func should always have a star. After all,
19510- // we are in a yield context.
19511- const functionFlags = func && getFunctionFlags(func);
19512- if (node.asteriskToken) {
19513- // Async generator functions prior to ESNext require the __await, __asyncDelegator,
19514- // and __asyncValues helpers
19515- if ((functionFlags & FunctionFlags.AsyncGenerator) === FunctionFlags.AsyncGenerator &&
19516- languageVersion < ScriptTarget.ESNext) {
19517- checkExternalEmitHelpers(node, ExternalEmitHelpers.AsyncDelegatorIncludes);
19518- }
19519-
19520- // Generator functions prior to ES2015 require the __values helper
19521- if ((functionFlags & FunctionFlags.AsyncGenerator) === FunctionFlags.Generator &&
19522- languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
19523- checkExternalEmitHelpers(node, ExternalEmitHelpers.Values);
19524- }
19525- }
19526-
19527- if (functionFlags & FunctionFlags.Generator) {
19528- const expressionType = checkExpressionCached(node.expression);
19529- let expressionElementType: Type;
19530- const nodeIsYieldStar = !!node.asteriskToken;
19531- if (nodeIsYieldStar) {
19532- expressionElementType = checkIteratedTypeOrElementType(expressionType, node.expression, /*allowStringInput*/ false, (functionFlags & FunctionFlags.Async) !== 0);
19533- }
19534-
19535- // There is no point in doing an assignability check if the function
19536- // has no explicit return type because the return type is directly computed
19537- // from the yield expressions.
19538- const returnType = getEffectiveReturnTypeNode(func);
19539- if (returnType) {
19540- const signatureElementType = getIteratedTypeOfGenerator(getTypeFromTypeNode(returnType), (functionFlags & FunctionFlags.Async) !== 0) || anyType;
19541- if (nodeIsYieldStar) {
19542- checkTypeAssignableTo(
19543- functionFlags & FunctionFlags.Async
19544- ? getAwaitedType(expressionElementType, node.expression, Diagnostics.Type_of_iterated_elements_of_a_yield_Asterisk_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member)
19545- : expressionElementType,
19546- signatureElementType,
19547- node.expression,
19548- /*headMessage*/ undefined);
19549- }
19550- else {
19551- checkTypeAssignableTo(
19552- functionFlags & FunctionFlags.Async
19553- ? getAwaitedType(expressionType, node.expression, Diagnostics.Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member)
19554- : expressionType,
19555- signatureElementType,
19556- node.expression,
19557- /*headMessage*/ undefined);
19558- }
19559- }
19503+ const func = getContainingFunction(node);
19504+ const functionFlags = func ? getFunctionFlags(func) : FunctionFlags.Normal;
19505+
19506+ if (!(functionFlags & FunctionFlags.Generator)) {
19507+ // If the user's code is syntactically correct, the func should always have a star. After all, we are in a yield context.
19508+ return anyType;
19509+ }
19510+
19511+ if (node.asteriskToken) {
19512+ // Async generator functions prior to ESNext require the __await, __asyncDelegator,
19513+ // and __asyncValues helpers
19514+ if ((functionFlags & FunctionFlags.AsyncGenerator) === FunctionFlags.AsyncGenerator &&
19515+ languageVersion < ScriptTarget.ESNext) {
19516+ checkExternalEmitHelpers(node, ExternalEmitHelpers.AsyncDelegatorIncludes);
19517+ }
19518+
19519+ // Generator functions prior to ES2015 require the __values helper
19520+ if ((functionFlags & FunctionFlags.AsyncGenerator) === FunctionFlags.Generator &&
19521+ languageVersion < ScriptTarget.ES2015 && compilerOptions.downlevelIteration) {
19522+ checkExternalEmitHelpers(node, ExternalEmitHelpers.Values);
1956019523 }
1956119524 }
1956219525
19526+ const isAsync = (functionFlags & FunctionFlags.Async) !== 0;
19527+ const yieldedType = getYieldedTypeOfYieldExpression(node, isAsync);
19528+ // There is no point in doing an assignability check if the function
19529+ // has no explicit return type because the return type is directly computed
19530+ // from the yield expressions.
19531+ const returnType = getEffectiveReturnTypeNode(func);
19532+ if (returnType) {
19533+ const signatureElementType = getIteratedTypeOfGenerator(getTypeFromTypeNode(returnType), isAsync) || anyType;
19534+ checkTypeAssignableTo(yieldedType, signatureElementType, node.expression || node, /*headMessage*/ undefined);
19535+ }
19536+
1956319537 // Both yield and yield* expressions have type 'any'
1956419538 return anyType;
1956519539 }
@@ -20711,12 +20685,12 @@ namespace ts {
2071120685 let hasOverloads = false;
2071220686 let bodyDeclaration: FunctionLikeDeclaration;
2071320687 let lastSeenNonAmbientDeclaration: FunctionLikeDeclaration;
20714- let previousDeclaration: FunctionLike ;
20688+ let previousDeclaration: SignatureDeclaration ;
2071520689
2071620690 const declarations = symbol.declarations;
2071720691 const isConstructor = (symbol.flags & SymbolFlags.Constructor) !== 0;
2071820692
20719- function reportImplementationExpectedError(node: FunctionLike ): void {
20693+ function reportImplementationExpectedError(node: SignatureDeclaration ): void {
2072020694 if (node.name && nodeIsMissing(node.name)) {
2072120695 return;
2072220696 }
@@ -20778,7 +20752,7 @@ namespace ts {
2077820752 let duplicateFunctionDeclaration = false;
2077920753 let multipleConstructorImplementation = false;
2078020754 for (const current of declarations) {
20781- const node = <FunctionLike >current;
20755+ const node = <SignatureDeclaration >current;
2078220756 const inAmbientContext = node.flags & NodeFlags.Ambient;
2078320757 const inAmbientContextOrInterface = node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.TypeLiteral || inAmbientContext;
2078420758 if (inAmbientContextOrInterface) {
@@ -22786,12 +22760,12 @@ namespace ts {
2278622760 // TODO: Check that target label is valid
2278722761 }
2278822762
22789- function isGetAccessorWithAnnotatedSetAccessor(node: FunctionLike ) {
22763+ function isGetAccessorWithAnnotatedSetAccessor(node: SignatureDeclaration ) {
2279022764 return node.kind === SyntaxKind.GetAccessor
2279122765 && getEffectiveSetAccessorTypeAnnotationNode(getDeclarationOfKind<SetAccessorDeclaration>(node.symbol, SyntaxKind.SetAccessor)) !== undefined;
2279222766 }
2279322767
22794- function isUnwrappedReturnTypeVoidOrAny(func: FunctionLike , returnType: Type): boolean {
22768+ function isUnwrappedReturnTypeVoidOrAny(func: SignatureDeclaration , returnType: Type): boolean {
2279522769 const unwrappedReturnType = (getFunctionFlags(func) & FunctionFlags.AsyncGenerator) === FunctionFlags.Async
2279622770 ? getPromisedTypeOfPromise(returnType) // Async function
2279722771 : returnType; // AsyncGenerator function, Generator function, or normal function
@@ -25512,7 +25486,7 @@ namespace ts {
2551225486 return false;
2551325487 }
2551425488
25515- function isImplementationOfOverload(node: FunctionLike ) {
25489+ function isImplementationOfOverload(node: SignatureDeclaration ) {
2551625490 if (nodeIsPresent((node as FunctionLikeDeclaration).body)) {
2551725491 const symbol = getSymbolOfNode(node);
2551825492 const signaturesOfSymbol = getSignaturesOfSymbol(symbol);
0 commit comments