@@ -1117,11 +1117,17 @@ namespace ts.Completions {
1117
1117
let type = typeChecker . getTypeOfSymbolAtLocation ( symbol , node ) . getNonOptionalType ( ) ;
1118
1118
let insertQuestionDot = false ;
1119
1119
if ( type . isNullableType ( ) ) {
1120
- insertQuestionDot = isRightOfDot && ! isRightOfQuestionDot ;
1121
- type = type . getNonNullableType ( ) ;
1122
- }
1123
- if ( insertQuestionDot && preferences . includeAutomaticOptionalChainCompletions === false ) {
1124
- return ;
1120
+ const canCorrectToQuestionDot =
1121
+ isRightOfDot &&
1122
+ ! isRightOfQuestionDot &&
1123
+ preferences . includeAutomaticOptionalChainCompletions !== false ;
1124
+
1125
+ if ( canCorrectToQuestionDot || isRightOfQuestionDot ) {
1126
+ type = type . getNonNullableType ( ) ;
1127
+ if ( canCorrectToQuestionDot ) {
1128
+ insertQuestionDot = true ;
1129
+ }
1130
+ }
1125
1131
}
1126
1132
addTypeProperties ( type , ! ! ( node . flags & NodeFlags . AwaitContext ) , insertQuestionDot ) ;
1127
1133
}
@@ -1141,11 +1147,17 @@ namespace ts.Completions {
1141
1147
let type = typeChecker . getTypeAtLocation ( node ) . getNonOptionalType ( ) ;
1142
1148
let insertQuestionDot = false ;
1143
1149
if ( type . isNullableType ( ) ) {
1144
- insertQuestionDot = isRightOfDot && ! isRightOfQuestionDot ;
1145
- type = type . getNonNullableType ( ) ;
1146
- }
1147
- if ( insertQuestionDot && preferences . includeAutomaticOptionalChainCompletions === false ) {
1148
- return ;
1150
+ const canCorrectToQuestionDot =
1151
+ isRightOfDot &&
1152
+ ! isRightOfQuestionDot &&
1153
+ preferences . includeAutomaticOptionalChainCompletions !== false ;
1154
+
1155
+ if ( canCorrectToQuestionDot || isRightOfQuestionDot ) {
1156
+ type = type . getNonNullableType ( ) ;
1157
+ if ( canCorrectToQuestionDot ) {
1158
+ insertQuestionDot = true ;
1159
+ }
1160
+ }
1149
1161
}
1150
1162
addTypeProperties ( type , ! ! ( node . flags & NodeFlags . AwaitContext ) , insertQuestionDot ) ;
1151
1163
}
0 commit comments