Skip to content

Commit 6418c2f

Browse files
authored
Merge pull request #12543 from wonderful-panda/fix-12536
tsserver: get candidates from <K extends keyof Foo> (fix #12536)
2 parents 69e0677 + aaf8773 commit 6418c2f

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ namespace ts {
114114
// we deliberately exclude augmentations
115115
// since we are only interested in declarations of the module itself
116116
return tryFindAmbientModule(moduleName, /*withAugmentations*/ false);
117-
}
117+
},
118+
getApparentType
118119
};
119120

120121
const tupleTypes: GenericType[] = [];

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,6 +2372,7 @@ namespace ts {
23722372
getAmbientModules(): Symbol[];
23732373

23742374
tryGetMemberInModuleExports(memberName: string, moduleSymbol: Symbol): Symbol | undefined;
2375+
getApparentType(type: Type): Type;
23752376

23762377
/* @internal */ tryFindAmbientModuleWithoutAugmentations(moduleName: string): Symbol;
23772378

src/services/completions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ namespace ts.Completions {
244244
}
245245

246246
function addStringLiteralCompletionsFromType(type: Type, result: CompletionEntry[]): void {
247+
if (type && type.flags & TypeFlags.TypeParameter) {
248+
type = typeChecker.getApparentType(type);
249+
}
247250
if (!type) {
248251
return;
249252
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////interface Foo {
4+
//// foo: string;
5+
//// bar: string;
6+
////}
7+
////
8+
////function f<K extends keyof Foo>(a: K) { };
9+
////f("/*1*/
10+
11+
goTo.marker('1');
12+
verify.completionListContains("foo");
13+
verify.completionListContains("bar");
14+
verify.memberListCount(2);
15+

0 commit comments

Comments
 (0)