Merge pull request #13478 from Microsoft/string_literal_rest_parameter

Support completions for string literal in rest parameter
This commit is contained in:
Andy 2017-01-17 06:40:15 -08:00 committed by GitHub
commit 4ba382a1d1
4 changed files with 17 additions and 4 deletions

View file

@ -84,6 +84,7 @@ namespace ts {
getIndexTypeOfType,
getBaseTypes,
getTypeFromTypeNode,
getParameterType: getTypeAtPosition,
getReturnTypeOfSignature,
getNonNullableType,
getSymbolsInScope,

View file

@ -2341,6 +2341,11 @@ namespace ts {
getIndexTypeOfType(type: Type, kind: IndexKind): Type;
getBaseTypes(type: InterfaceType): ObjectType[];
getReturnTypeOfSignature(signature: Signature): Type;
/**
* Gets the type of a parameter at a given position in a signature.
* Returns `any` if the index is not valid.
*/
/* @internal */ getParameterType(signature: Signature, parameterIndex: number): Type;
getNonNullableType(type: Type): Type;
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];

View file

@ -204,10 +204,7 @@ namespace ts.Completions {
typeChecker.getResolvedSignature(argumentInfo.invocation, candidates);
for (const candidate of candidates) {
if (candidate.parameters.length > argumentInfo.argumentIndex) {
const parameter = candidate.parameters[argumentInfo.argumentIndex];
addStringLiteralCompletionsFromType(typeChecker.getTypeAtLocation(parameter.valueDeclaration), entries);
}
addStringLiteralCompletionsFromType(typeChecker.getParameterType(candidate, argumentInfo.argumentIndex), entries);
}
if (entries.length) {

View file

@ -0,0 +1,10 @@
/// <reference path='fourslash.ts'/>
////type T = "foo" | "bar";
////type U = "oof" | "rab";
////function f(x: T, ...args: U[]) { };
////f("/*1*/", "/*2*/", "/*3*/");
verify.completionsAt("1", ["foo", "bar"]);
verify.completionsAt("2", ["oof", "rab"]);
verify.completionsAt("3", ["oof", "rab"]);