In addStringLiteralCompletionsFromType, use getBaseConstraintOfType instead of getApparentType

This commit is contained in:
Andy Hanson 2017-05-08 10:33:48 -07:00
parent b4caf646ea
commit 9e03d42fda
4 changed files with 21 additions and 2 deletions

View file

@ -204,7 +204,8 @@ namespace ts {
// since we are only interested in declarations of the module itself
return tryFindAmbientModule(moduleName, /*withAugmentations*/ false);
},
getApparentType
getApparentType,
getBaseConstraintOfType,
};
const tupleTypes: GenericType[] = [];

View file

@ -2552,6 +2552,7 @@ namespace ts {
tryGetMemberInModuleExports(memberName: string, moduleSymbol: Symbol): Symbol | undefined;
getApparentType(type: Type): Type;
/* @internal */ getBaseConstraintOfType(type: Type): Type;
/* @internal */ tryFindAmbientModuleWithoutAugmentations(moduleName: string): Symbol;

View file

@ -260,7 +260,7 @@ namespace ts.Completions {
function addStringLiteralCompletionsFromType(type: Type, result: Push<CompletionEntry>, typeChecker: TypeChecker): void {
if (type && type.flags & TypeFlags.TypeParameter) {
type = typeChecker.getApparentType(type);
type = typeChecker.getBaseConstraintOfType(type);
}
if (!type) {
return;

View file

@ -0,0 +1,17 @@
/// <reference path="fourslash.ts" />
////interface A { a: number; };
////interface B { a: number; b: number; };
////function f<T extends keyof A>(key: T) {}
////f("/*f*/");
////function g<T extends keyof B>(key: T) {}
////g("/*g*/");
goTo.marker("f");
verify.completionListCount(1);
verify.completionListContains("a");
goTo.marker("g");
verify.completionListCount(2);
verify.completionListContains("a");
verify.completionListContains("b");