@@ -392,7 +392,7 @@ function getStringLiteralCompletionEntries(sourceFile: SourceFile, node: StringL
392392 // });
393393 return stringLiteralCompletionsForObjectLiteral ( typeChecker , parent . parent ) ;
394394 }
395- return fromContextualType ( ) ;
395+ return fromContextualType ( ) || fromContextualType ( ContextFlags . None ) ;
396396
397397 case SyntaxKind . ElementAccessExpression : {
398398 const { expression, argumentExpression } = parent as ElementAccessExpression ;
@@ -432,16 +432,24 @@ function getStringLiteralCompletionEntries(sourceFile: SourceFile, node: StringL
432432 return { kind : StringLiteralCompletionKind . Paths , paths : getStringLiteralCompletionsFromModuleNames ( sourceFile , node , compilerOptions , host , typeChecker , preferences ) } ;
433433 case SyntaxKind . CaseClause :
434434 const tracker = newCaseClauseTracker ( typeChecker , ( parent as CaseClause ) . parent . clauses ) ;
435- const literals = fromContextualType ( ) . types . filter ( literal => ! tracker . hasValue ( literal . value ) ) ;
435+ const contextualTypes = fromContextualType ( ) ;
436+ if ( ! contextualTypes ) {
437+ return ;
438+ }
439+ const literals = contextualTypes . types . filter ( literal => ! tracker . hasValue ( literal . value ) ) ;
436440 return { kind : StringLiteralCompletionKind . Types , types : literals , isNewIdentifier : false } ;
437441 default :
438442 return fromContextualType ( ) ;
439443 }
440444
441- function fromContextualType ( ) : StringLiteralCompletionsFromTypes {
445+ function fromContextualType ( contextFlags : ContextFlags = ContextFlags . Completions ) : StringLiteralCompletionsFromTypes | undefined {
442446 // Get completion for string literal from string literal type
443447 // i.e. var x: "hi" | "hello" = "/*completion position*/"
444- return { kind : StringLiteralCompletionKind . Types , types : getStringLiteralTypes ( getContextualTypeFromParent ( node , typeChecker , ContextFlags . Completions ) ) , isNewIdentifier : false } ;
448+ const types = getStringLiteralTypes ( getContextualTypeFromParent ( node , typeChecker , contextFlags ) ) ;
449+ if ( ! types . length ) {
450+ return ;
451+ }
452+ return { kind : StringLiteralCompletionKind . Types , types, isNewIdentifier : false } ;
445453 }
446454}
447455
0 commit comments