mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-12 21:37:41 -06:00
Support completions for string literal in rest parameter
This commit is contained in:
parent
d86d850211
commit
f1b481a1b6
@ -84,6 +84,7 @@ namespace ts {
|
||||
getIndexTypeOfType,
|
||||
getBaseTypes,
|
||||
getTypeFromTypeNode,
|
||||
getParameterType: getTypeAtPosition,
|
||||
getReturnTypeOfSignature,
|
||||
getNonNullableType,
|
||||
getSymbolsInScope,
|
||||
|
||||
@ -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[];
|
||||
|
||||
@ -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) {
|
||||
|
||||
10
tests/cases/fourslash/completionForStringLiteral7.ts
Normal file
10
tests/cases/fourslash/completionForStringLiteral7.ts
Normal 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"]);
|
||||
Loading…
x
Reference in New Issue
Block a user