Skip to content

Commit f1904a9

Browse files
committed
fix completions for string literal types with template string (microsoft#19162)
1 parent 40efd1b commit f1904a9

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/services/completions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ namespace ts.Completions {
213213

214214
function getStringLiteralCompletionEntries(sourceFile: SourceFile, position: number, typeChecker: TypeChecker, compilerOptions: CompilerOptions, host: LanguageServiceHost, log: Log): CompletionInfo | undefined {
215215
const node = findPrecedingToken(position, sourceFile);
216-
if (!node || node.kind !== SyntaxKind.StringLiteral) {
216+
if (!node || (node.kind !== SyntaxKind.StringLiteral && node.kind !== SyntaxKind.NoSubstitutionTemplateLiteral)) {
217217
return undefined;
218218
}
219219

@@ -278,7 +278,7 @@ namespace ts.Completions {
278278

279279
// Get completion for string literal from string literal type
280280
// i.e. var x: "hi" | "hello" = "/*completion position*/"
281-
return getStringLiteralCompletionEntriesFromType(typeChecker.getContextualType(<StringLiteral>node), typeChecker);
281+
return getStringLiteralCompletionEntriesFromType(typeChecker.getContextualType(<LiteralExpression>node), typeChecker);
282282
}
283283
}
284284

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////let count: 'one' | 'two';
4+
////count = `/**/`
5+
6+
goTo.marker();
7+
verify.completionListContains('one');
8+
verify.completionListContains('two');

0 commit comments

Comments
 (0)