File tree 2 files changed +17
-1
lines changed 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,10 @@ namespace ts.codefix {
37
37
let suggestion : string | undefined ;
38
38
if ( isPropertyAccessExpression ( node . parent ) && node . parent . name === node ) {
39
39
Debug . assert ( node . kind === SyntaxKind . Identifier , "Expected an identifier for spelling (property access)" ) ;
40
- const containingType = checker . getTypeAtLocation ( node . parent . expression ) ;
40
+ let containingType = checker . getTypeAtLocation ( node . parent . expression ) ;
41
+ if ( node . parent . flags & NodeFlags . OptionalChain ) {
42
+ containingType = checker . getNonNullableType ( containingType ) ;
43
+ }
41
44
suggestion = checker . getSuggestionForNonexistentProperty ( node as Identifier , containingType ) ;
42
45
}
43
46
else if ( isImportSpecifier ( node . parent ) && node . parent . name === node ) {
Original file line number Diff line number Diff line change
1
+ /// <reference path="fourslash.ts" />
2
+
3
+ // @strict : true
4
+
5
+ ////function f(x: string | null) {
6
+ //// [|x?.toLowrCase();|]
7
+ //// }
8
+
9
+ verify . rangeAfterCodeFix (
10
+ `x?.toLowerCase();` ,
11
+ /*includeWhiteSpace*/ false ,
12
+ /*errorCode*/ undefined ,
13
+ /*index*/ 0 ) ;
You can’t perform that action at this time.
0 commit comments