Merge pull request #19204 from Kingwl/fix-completions-with-template-literal-type

fix completions for string literal types with template string (#19162)
This commit is contained in:
Daniel Rosenwasser 2017-12-19 11:18:21 -08:00 committed by GitHub
commit 89b5d8cb14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -238,7 +238,7 @@ namespace ts.Completions {
function getStringLiteralCompletionEntries(sourceFile: SourceFile, position: number, typeChecker: TypeChecker, compilerOptions: CompilerOptions, host: LanguageServiceHost, log: Log): CompletionInfo | undefined {
const node = findPrecedingToken(position, sourceFile);
if (!node || node.kind !== SyntaxKind.StringLiteral) {
if (!node || (node.kind !== SyntaxKind.StringLiteral && node.kind !== SyntaxKind.NoSubstitutionTemplateLiteral)) {
return undefined;
}
@ -303,7 +303,7 @@ namespace ts.Completions {
// Get completion for string literal from string literal type
// i.e. var x: "hi" | "hello" = "/*completion position*/"
return getStringLiteralCompletionEntriesFromType(typeChecker.getContextualType(<StringLiteral>node), typeChecker);
return getStringLiteralCompletionEntriesFromType(typeChecker.getContextualType(<LiteralExpression>node), typeChecker);
}
}

View File

@ -0,0 +1,8 @@
/// <reference path="fourslash.ts" />
////let count: 'one' | 'two';
////count = `/**/`
goTo.marker();
verify.completionListContains('one');
verify.completionListContains('two');