@@ -12,47 +12,61 @@ namespace ts.codefix {
12
12
// This is the identifier in the case of a class declaration
13
13
// or the class keyword token in the case of a class expression.
14
14
const token = getTokenAtPosition ( sourceFile , start ) ;
15
- const checker = context . program . getTypeChecker ( ) ;
16
15
17
- if ( ! ( token . parent && token . parent . kind === SyntaxKind . PropertyAccessExpression ) ) {
16
+ const classDeclaration = getContainingClass ( token ) ;
17
+ if ( ! classDeclaration ) {
18
18
return undefined ;
19
19
}
20
20
21
- if ( ( token . parent as PropertyAccessExpression ) . expression . kind !== SyntaxKind . ThisKeyword ) {
21
+ const startPos = classDeclaration . members . pos ;
22
+
23
+ if ( ! ( token . parent && token . parent . kind === SyntaxKind . PropertyAccessExpression ) ) {
22
24
return undefined ;
23
25
}
24
- 1 + 1 ;
26
+
27
+ if ( ( token . parent as PropertyAccessExpression ) . expression . kind !== SyntaxKind . ThisKeyword ) {
28
+ return undefined ;
29
+ }
30
+
31
+ // if function call, synthesize function declaration
32
+ if ( token . parent . parent . kind == SyntaxKind . CallExpression ) {
33
+
34
+ }
25
35
26
36
let typeString : string = 'any' ;
37
+
27
38
// if binary expression, try to infer type for LHS, else use any
28
- if ( token . parent . parent . kind === SyntaxKind . BinaryExpression )
29
- {
39
+ if ( token . parent . parent . kind === SyntaxKind . BinaryExpression ) {
30
40
const binaryExpression = token . parent . parent as BinaryExpression ;
31
41
binaryExpression . operatorToken ;
32
-
33
- const type = checker . getTypeAtLocation ( binaryExpression . right ) ;
42
+
43
+ const checker = context . program . getTypeChecker ( ) ;
44
+ const type = checker . getWidenedType ( checker . getTypeAtLocation ( binaryExpression . right ) ) ;
34
45
typeString = checker . typeToString ( type ) ;
35
46
}
36
47
37
- const classDeclaration = getContainingClass ( token ) ;
38
- const startPos = classDeclaration . members . pos ;
39
48
return [ {
40
- description : getLocaleSpecificMessage ( Diagnostics . Implement_inherited_abstract_class ) ,
49
+ description : formatStringFromArgs ( getLocaleSpecificMessage ( Diagnostics . Add_declaration_for_missing_property_0 ) , [ token . getText ( ) ] ) ,
41
50
changes : [ {
42
51
fileName : sourceFile . fileName ,
43
52
textChanges : [ {
44
53
span : { start : startPos , length : 0 } ,
45
54
newText : `${ token . getFullText ( sourceFile ) } : ${ typeString } ;`
46
55
} ]
47
56
} ]
57
+ } ,
58
+ {
59
+ description : formatStringFromArgs ( getLocaleSpecificMessage ( Diagnostics . Add_index_accessor_for_missing_property_0 ) , [ token . getText ( ) ] ) ,
60
+ changes : [ {
61
+ fileName : sourceFile . fileName ,
62
+ textChanges : [ {
63
+ span : { start : startPos , length : 0 } ,
64
+ newText : `[name: string]: ${ typeString } ;`
65
+ } ]
66
+ } ]
48
67
} ] ;
49
68
}
50
69
51
-
52
-
53
-
54
- // x needs to be a `this` construct. ie
55
- // this.<thing>.
56
70
// Want to infer type of x when possible. ie:
57
71
// * assignment,
58
72
// * function call argument: foo<T>(this.x) where foo(x: SomeType<T>)
@@ -65,10 +79,4 @@ namespace ts.codefix {
65
79
// inferred type might be error. then add any.
66
80
// either make indexable of the inferred type
67
81
// add named member of the inferred type.
68
- }
69
-
70
- // // class C {
71
- // // constructor() {
72
- // // this.x = 1;
73
- // // }
74
- // // }
82
+ }
0 commit comments