@@ -7,12 +7,16 @@ namespace ts.codefix {
7
7
Diagnostics . Cannot_find_name_0_Did_you_mean_the_instance_member_this_0 . code ,
8
8
Diagnostics . Cannot_find_name_0_Did_you_mean_the_static_member_1_0 . code ,
9
9
Diagnostics . Module_0_has_no_exported_member_1_Did_you_mean_2 . code ,
10
+ // for JSX class components
11
+ Diagnostics . No_overload_matches_this_call . code ,
12
+ // for JSX FC
13
+ Diagnostics . Type_0_is_not_assignable_to_type_1 . code ,
10
14
] ;
11
15
registerCodeFix ( {
12
16
errorCodes,
13
17
getCodeActions ( context ) {
14
- const { sourceFile } = context ;
15
- const info = getInfo ( sourceFile , context . span . start , context ) ;
18
+ const { sourceFile, errorCode } = context ;
19
+ const info = getInfo ( sourceFile , context . span . start , context , errorCode ) ;
16
20
if ( ! info ) return undefined ;
17
21
const { node, suggestedSymbol } = info ;
18
22
const { target } = context . host . getCompilationSettings ( ) ;
@@ -21,18 +25,23 @@ namespace ts.codefix {
21
25
} ,
22
26
fixIds : [ fixId ] ,
23
27
getAllCodeActions : context => codeFixAll ( context , errorCodes , ( changes , diag ) => {
24
- const info = getInfo ( diag . file , diag . start , context ) ;
28
+ const info = getInfo ( diag . file , diag . start , context , diag . code ) ;
25
29
const { target } = context . host . getCompilationSettings ( ) ;
26
30
if ( info ) doChange ( changes , context . sourceFile , info . node , info . suggestedSymbol , target ! ) ;
27
31
} ) ,
28
32
} ) ;
29
33
30
- function getInfo ( sourceFile : SourceFile , pos : number , context : CodeFixContextBase ) : { node : Node , suggestedSymbol : Symbol } | undefined {
34
+ function getInfo ( sourceFile : SourceFile , pos : number , context : CodeFixContextBase , errorCode : number ) : { node : Node , suggestedSymbol : Symbol } | undefined {
31
35
// This is the identifier of the misspelled word. eg:
32
36
// this.speling = 1;
33
37
// ^^^^^^^
34
38
const node = getTokenAtPosition ( sourceFile , pos ) ;
35
39
const parent = node . parent ;
40
+ // Only fix spelling for No_overload_matches_this_call emitted on the React class component
41
+ if ( (
42
+ errorCode === Diagnostics . No_overload_matches_this_call . code ||
43
+ errorCode === Diagnostics . Type_0_is_not_assignable_to_type_1 . code ) &&
44
+ ! isJsxAttribute ( parent ) ) return undefined ;
36
45
const checker = context . program . getTypeChecker ( ) ;
37
46
38
47
let suggestedSymbol : Symbol | undefined ;
0 commit comments