Skip to content

Commit abb2b82

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

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/compiler/checker.ts

Lines 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[] = [];

src/compiler/types.ts

Lines 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

src/services/completions.ts

Lines 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;
Lines 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)