@@ -392,7 +392,7 @@ function getStringLiteralCompletionEntries(sourceFile: SourceFile, node: StringL
392
392
// });
393
393
return stringLiteralCompletionsForObjectLiteral ( typeChecker , parent . parent ) ;
394
394
}
395
- return fromContextualType ( ) ;
395
+ return fromContextualType ( ) || fromContextualType ( ContextFlags . None ) ;
396
396
397
397
case SyntaxKind . ElementAccessExpression : {
398
398
const { expression, argumentExpression } = parent as ElementAccessExpression ;
@@ -432,16 +432,24 @@ function getStringLiteralCompletionEntries(sourceFile: SourceFile, node: StringL
432
432
return { kind : StringLiteralCompletionKind . Paths , paths : getStringLiteralCompletionsFromModuleNames ( sourceFile , node , compilerOptions , host , typeChecker , preferences ) } ;
433
433
case SyntaxKind . CaseClause :
434
434
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 ) ) ;
436
440
return { kind : StringLiteralCompletionKind . Types , types : literals , isNewIdentifier : false } ;
437
441
default :
438
442
return fromContextualType ( ) ;
439
443
}
440
444
441
- function fromContextualType ( ) : StringLiteralCompletionsFromTypes {
445
+ function fromContextualType ( contextFlags : ContextFlags = ContextFlags . Completions ) : StringLiteralCompletionsFromTypes | undefined {
442
446
// Get completion for string literal from string literal type
443
447
// 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 } ;
445
453
}
446
454
}
447
455
0 commit comments