fix completions for string literal types with template string (#19162)

This commit is contained in:
kingwl
2017-10-16 15:50:04 +08:00
parent 40efd1b3bd
commit f1904a93f5
2 changed files with 10 additions and 2 deletions

View File

@@ -213,7 +213,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;
}
@@ -278,7 +278,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');