Skip to content

Commit

Permalink
Merge pull request microsoft#19204 from Kingwl/fix-completions-with-t…
Browse files Browse the repository at this point in the history
…emplate-literal-type

 fix completions for string literal types with template string (microsoft#19162)
  • Loading branch information
DanielRosenwasser authored Dec 19, 2017
2 parents 1c4b9a5 + f1904a9 commit 89b5d8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// <reference path="fourslash.ts" />

////let count: 'one' | 'two';
////count = `/**/`

goTo.marker();
verify.completionListContains('one');
verify.completionListContains('two');

0 comments on commit 89b5d8c

Please sign in to comment.