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 abb2b82

Browse filesBrowse files
author
Andy
authored
Merge pull request microsoft#15668 from Microsoft/completions-keyof
In addStringLiteralCompletionsFromType, use getBaseConstraintOfType instead of getApparentType
2 parents 57d57a3 + 9e03d42 commit abb2b82
Copy full SHA for abb2b82

4 files changed

+21-2Lines changed: 21 additions & 2 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
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ namespace ts {
204204
// since we are only interested in declarations of the module itself
205205
return tryFindAmbientModule(moduleName, /*withAugmentations*/ false);
206206
},
207-
getApparentType
207+
getApparentType,
208+
getBaseConstraintOfType,
208209
};
209210

210211
const tupleTypes: GenericType[] = [];
Collapse file

‎src/compiler/types.ts‎

Copy file name to clipboardExpand all lines: src/compiler/types.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,6 +2552,7 @@ namespace ts {
25522552

25532553
tryGetMemberInModuleExports(memberName: string, moduleSymbol: Symbol): Symbol | undefined;
25542554
getApparentType(type: Type): Type;
2555+
/* @internal */ getBaseConstraintOfType(type: Type): Type;
25552556

25562557
/* @internal */ tryFindAmbientModuleWithoutAugmentations(moduleName: string): Symbol;
25572558

Collapse file

‎src/services/completions.ts‎

Copy file name to clipboardExpand all lines: src/services/completions.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ namespace ts.Completions {
260260

261261
function addStringLiteralCompletionsFromType(type: Type, result: Push<CompletionEntry>, typeChecker: TypeChecker): void {
262262
if (type && type.flags & TypeFlags.TypeParameter) {
263-
type = typeChecker.getApparentType(type);
263+
type = typeChecker.getBaseConstraintOfType(type);
264264
}
265265
if (!type) {
266266
return;
Collapse file
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////interface A { a: number; };
4+
////interface B { a: number; b: number; };
5+
////function f<T extends keyof A>(key: T) {}
6+
////f("/*f*/");
7+
////function g<T extends keyof B>(key: T) {}
8+
////g("/*g*/");
9+
10+
goTo.marker("f");
11+
verify.completionListCount(1);
12+
verify.completionListContains("a");
13+
14+
goTo.marker("g");
15+
verify.completionListCount(2);
16+
verify.completionListContains("a");
17+
verify.completionListContains("b");

0 commit comments

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