Skip to content

Commit d620129

Browse files
author
Andy
authored
Ensure getResolvedSignature never returns undefined (microsoft#18883)
1 parent 2df7058 commit d620129

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16561,10 +16561,9 @@ namespace ts {
1656116561
* @param candidatesOutArray an array of signature to be filled in by the function. It is passed by signature help in the language service;
1656216562
* the function will fill it up with appropriate candidate signatures
1656316563
*/
16564-
function getResolvedJsxStatelessFunctionSignature(openingLikeElement: JsxOpeningLikeElement, elementType: Type, candidatesOutArray: Signature[]): Signature {
16564+
function getResolvedJsxStatelessFunctionSignature(openingLikeElement: JsxOpeningLikeElement, elementType: Type, candidatesOutArray: Signature[]): Signature | undefined {
1656516565
Debug.assert(!(elementType.flags & TypeFlags.Union));
16566-
const callSignature = resolveStatelessJsxOpeningLikeElement(openingLikeElement, elementType, candidatesOutArray);
16567-
return callSignature;
16566+
return resolveStatelessJsxOpeningLikeElement(openingLikeElement, elementType, candidatesOutArray);
1656816567
}
1656916568

1657016569
/**
@@ -16576,7 +16575,7 @@ namespace ts {
1657616575
* @return a resolved signature if we can find function matching function signature through resolve call or a first signature in the list of functions.
1657716576
* otherwise return undefined if tag-name of the opening-like element doesn't have call signatures
1657816577
*/
16579-
function resolveStatelessJsxOpeningLikeElement(openingLikeElement: JsxOpeningLikeElement, elementType: Type, candidatesOutArray: Signature[]): Signature {
16578+
function resolveStatelessJsxOpeningLikeElement(openingLikeElement: JsxOpeningLikeElement, elementType: Type, candidatesOutArray: Signature[]): Signature | undefined {
1658016579
// 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)
1658116580
if (elementType.flags & TypeFlags.Union) {
1658216581
const types = (elementType as UnionType).types;
@@ -16609,7 +16608,7 @@ namespace ts {
1660916608
case SyntaxKind.JsxOpeningElement:
1661016609
case SyntaxKind.JsxSelfClosingElement:
1661116610
// This code-path is called by language service
16612-
return resolveStatelessJsxOpeningLikeElement(<JsxOpeningLikeElement>node, checkExpression((<JsxOpeningLikeElement>node).tagName), candidatesOutArray);
16611+
return resolveStatelessJsxOpeningLikeElement(<JsxOpeningLikeElement>node, checkExpression((<JsxOpeningLikeElement>node).tagName), candidatesOutArray) || unknownSignature;
1661316612
}
1661416613
Debug.assertNever(node, "Branch in 'resolveSignature' should be unreachable.");
1661516614
}

src/compiler/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,10 +2652,10 @@ namespace ts {
26522652
getRootSymbols(symbol: Symbol): Symbol[];
26532653
getContextualType(node: Expression): Type | undefined;
26542654
/**
2655-
* returns unknownSignature in the case of an error. Don't know when it returns undefined.
2655+
* returns unknownSignature in the case of an error.
26562656
* @param argumentCount Apparent number of arguments, passed in case of a possibly incomplete call. This should come from an ArgumentListInfo. See `signatureHelp.ts`.
26572657
*/
2658-
getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[], argumentCount?: number): Signature | undefined;
2658+
getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[], argumentCount?: number): Signature;
26592659
getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature | undefined;
26602660
isImplementationOfOverload(node: FunctionLike): boolean | undefined;
26612661
isUndefinedSymbol(symbol: Symbol): boolean;

src/services/symbolDisplay.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ namespace ts.SymbolDisplay {
136136
if (callExpressionLike) {
137137
const candidateSignatures: Signature[] = [];
138138
signature = typeChecker.getResolvedSignature(callExpressionLike, candidateSignatures);
139-
if (!signature && candidateSignatures.length) {
140-
// Use the first candidate:
141-
signature = candidateSignatures[0];
142-
}
143139

144140
const useConstructSignatures = callExpressionLike.kind === SyntaxKind.NewExpression || (isCallExpression(callExpressionLike) && callExpressionLike.expression.kind === SyntaxKind.SuperKeyword);
145141

0 commit comments

Comments
 (0)