From d620129d4a50457146e390d791aa4484a6c64df6 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 2 Oct 2017 17:02:27 -0700 Subject: [PATCH] Ensure getResolvedSignature never returns `undefined` (#18883) --- src/compiler/checker.ts | 9 ++++----- src/compiler/types.ts | 4 ++-- src/services/symbolDisplay.ts | 4 ---- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e3ba62bf3be..1c1ccd87d3c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16561,10 +16561,9 @@ namespace ts { * @param candidatesOutArray an array of signature to be filled in by the function. It is passed by signature help in the language service; * the function will fill it up with appropriate candidate signatures */ - function getResolvedJsxStatelessFunctionSignature(openingLikeElement: JsxOpeningLikeElement, elementType: Type, candidatesOutArray: Signature[]): Signature { + function getResolvedJsxStatelessFunctionSignature(openingLikeElement: JsxOpeningLikeElement, elementType: Type, candidatesOutArray: Signature[]): Signature | undefined { Debug.assert(!(elementType.flags & TypeFlags.Union)); - const callSignature = resolveStatelessJsxOpeningLikeElement(openingLikeElement, elementType, candidatesOutArray); - return callSignature; + return resolveStatelessJsxOpeningLikeElement(openingLikeElement, elementType, candidatesOutArray); } /** @@ -16576,7 +16575,7 @@ namespace ts { * @return a resolved signature if we can find function matching function signature through resolve call or a first signature in the list of functions. * otherwise return undefined if tag-name of the opening-like element doesn't have call signatures */ - function resolveStatelessJsxOpeningLikeElement(openingLikeElement: JsxOpeningLikeElement, elementType: Type, candidatesOutArray: Signature[]): Signature { + function resolveStatelessJsxOpeningLikeElement(openingLikeElement: JsxOpeningLikeElement, elementType: Type, candidatesOutArray: Signature[]): Signature | undefined { // If this function is called from language service, elementType can be a union type. This is not possible if the function is called from compiler (see: resolveCustomJsxElementAttributesType) if (elementType.flags & TypeFlags.Union) { const types = (elementType as UnionType).types; @@ -16609,7 +16608,7 @@ namespace ts { case SyntaxKind.JsxOpeningElement: case SyntaxKind.JsxSelfClosingElement: // This code-path is called by language service - return resolveStatelessJsxOpeningLikeElement(node, checkExpression((node).tagName), candidatesOutArray); + return resolveStatelessJsxOpeningLikeElement(node, checkExpression((node).tagName), candidatesOutArray) || unknownSignature; } Debug.assertNever(node, "Branch in 'resolveSignature' should be unreachable."); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 01036862980..6d94b2b0d95 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2652,10 +2652,10 @@ namespace ts { getRootSymbols(symbol: Symbol): Symbol[]; getContextualType(node: Expression): Type | undefined; /** - * returns unknownSignature in the case of an error. Don't know when it returns undefined. + * returns unknownSignature in the case of an error. * @param argumentCount Apparent number of arguments, passed in case of a possibly incomplete call. This should come from an ArgumentListInfo. See `signatureHelp.ts`. */ - getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[], argumentCount?: number): Signature | undefined; + getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[], argumentCount?: number): Signature; getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature | undefined; isImplementationOfOverload(node: FunctionLike): boolean | undefined; isUndefinedSymbol(symbol: Symbol): boolean; diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index ad8e7ddf975..a399610d823 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -136,10 +136,6 @@ namespace ts.SymbolDisplay { if (callExpressionLike) { const candidateSignatures: Signature[] = []; signature = typeChecker.getResolvedSignature(callExpressionLike, candidateSignatures); - if (!signature && candidateSignatures.length) { - // Use the first candidate: - signature = candidateSignatures[0]; - } const useConstructSignatures = callExpressionLike.kind === SyntaxKind.NewExpression || (isCallExpression(callExpressionLike) && callExpressionLike.expression.kind === SyntaxKind.SuperKeyword);