Improved argument description for parameters originating from tuples that were extracted from functions. (ie mapped functions)

This commit is contained in:
Titian Cernicova-Dragomir
2019-02-25 18:18:00 +02:00
parent c37254e509
commit 8d66d55de1
4 changed files with 69 additions and 2 deletions

View File

@@ -112,6 +112,7 @@ namespace ts {
getMergedSymbol,
getDiagnostics,
getGlobalDiagnostics,
getExpandedParameters,
getTypeOfSymbolAtLocation: (symbol, location) => {
location = getParseTreeNode(location);
return location ? getTypeOfSymbolAtLocation(symbol, location) : errorType;

View File

@@ -3032,6 +3032,7 @@ namespace ts {
/* @internal */
getPromisedTypeOfPromise(promise: Type, errorNode?: Node): Type | undefined;
getReturnTypeOfSignature(signature: Signature): Type;
/* @internal */ getExpandedParameters(sig: Signature): ReadonlyArray<Symbol>;
/**
* Gets the type of a parameter at a given position in a signature.
* Returns `any` if the index is not valid.

View File

@@ -566,7 +566,7 @@ namespace ts.SignatureHelp {
}
function itemInfoForParameters(candidateSignature: Signature, checker: TypeChecker, enclosingDeclaration: Node, sourceFile: SourceFile): SignatureHelpItemInfo {
const isVariadic = candidateSignature.hasRestParameter;
let isVariadic = candidateSignature.hasRestParameter;
const printer = createPrinter({ removeComments: true });
const typeParameterParts = mapToDisplayParts(writer => {
if (candidateSignature.typeParameters && candidateSignature.typeParameters.length) {
@@ -574,7 +574,16 @@ namespace ts.SignatureHelp {
printer.writeList(ListFormat.TypeParameters, args, sourceFile, writer);
}
});
const parameters = candidateSignature.parameters.map(p => createSignatureHelpParameterForParameter(p, checker, enclosingDeclaration, sourceFile, printer));
const expandedParameters = checker.getExpandedParameters(candidateSignature);
const parameters = expandedParameters.map(p => createSignatureHelpParameterForParameter(p, checker, enclosingDeclaration, sourceFile, printer));
// If parameters are not the same as the expanded parameters, we need to reevaluate whether this a variadic signature based on the last parameter
if (expandedParameters !== candidateSignature.parameters) {
const restCandidate = lastOrUndefined(expandedParameters);
isVariadic = !!restCandidate && !!(getCheckFlags(restCandidate) & CheckFlags.RestParameter);
}
return { isVariadic, parameters, prefix: [...typeParameterParts, punctuationPart(SyntaxKind.OpenParenToken)], suffix: [punctuationPart(SyntaxKind.CloseParenToken)] };
}