Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f1b481a

Browse filesBrowse files
author
Andy Hanson
committed
Support completions for string literal in rest parameter
1 parent d86d850 commit f1b481a
Copy full SHA for f1b481a

4 files changed

+17-4Lines changed: 17 additions & 4 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ namespace ts {
8484
getIndexTypeOfType,
8585
getBaseTypes,
8686
getTypeFromTypeNode,
87+
getParameterType: getTypeAtPosition,
8788
getReturnTypeOfSignature,
8889
getNonNullableType,
8990
getSymbolsInScope,
Collapse file

‎src/compiler/types.ts‎

Copy file name to clipboardExpand all lines: src/compiler/types.ts
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,6 +2341,11 @@ namespace ts {
23412341
getIndexTypeOfType(type: Type, kind: IndexKind): Type;
23422342
getBaseTypes(type: InterfaceType): ObjectType[];
23432343
getReturnTypeOfSignature(signature: Signature): Type;
2344+
/**
2345+
* Gets the type of a parameter at a given position in a signature.
2346+
* Returns `any` if the index is not valid.
2347+
*/
2348+
/* @internal */ getParameterType(signature: Signature, parameterIndex: number): Type;
23442349
getNonNullableType(type: Type): Type;
23452350

23462351
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
Collapse file

‎src/services/completions.ts‎

Copy file name to clipboardExpand all lines: src/services/completions.ts
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,7 @@ namespace ts.Completions {
204204
typeChecker.getResolvedSignature(argumentInfo.invocation, candidates);
205205

206206
for (const candidate of candidates) {
207-
if (candidate.parameters.length > argumentInfo.argumentIndex) {
208-
const parameter = candidate.parameters[argumentInfo.argumentIndex];
209-
addStringLiteralCompletionsFromType(typeChecker.getTypeAtLocation(parameter.valueDeclaration), entries);
210-
}
207+
addStringLiteralCompletionsFromType(typeChecker.getParameterType(candidate, argumentInfo.argumentIndex), entries);
211208
}
212209

213210
if (entries.length) {
Collapse file
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////type T = "foo" | "bar";
4+
////type U = "oof" | "rab";
5+
////function f(x: T, ...args: U[]) { };
6+
////f("/*1*/", "/*2*/", "/*3*/");
7+
8+
verify.completionsAt("1", ["foo", "bar"]);
9+
verify.completionsAt("2", ["oof", "rab"]);
10+
verify.completionsAt("3", ["oof", "rab"]);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.