1
+ /* @internal */
2
+ namespace ts . codefix {
3
+ registerCodeFix ( {
4
+ errorCodes : [ Diagnostics . Property_0_does_not_exist_on_type_1 . code ] ,
5
+ getCodeActions : getActionsForAddMissingMember
6
+ } ) ;
7
+
8
+ function getActionsForAddMissingMember ( context : CodeFixContext ) : CodeAction [ ] | undefined {
9
+
10
+ const sourceFile = context . sourceFile ;
11
+ const start = context . span . start ;
12
+ // This is the identifier in the case of a class declaration
13
+ // or the class keyword token in the case of a class expression.
14
+ const token = getTokenAtPosition ( sourceFile , start ) ;
15
+ const checker = context . program . getTypeChecker ( ) ;
16
+
17
+ if ( ! ( token . parent && token . parent . kind === SyntaxKind . PropertyAccessExpression ) ) {
18
+ return undefined ;
19
+ }
20
+
21
+ if ( ( token . parent as PropertyAccessExpression ) . expression . kind !== SyntaxKind . ThisKeyword ) {
22
+ return undefined ;
23
+ }
24
+ 1 + 1 ;
25
+
26
+ let typeString : string = 'any' ;
27
+ // if binary expression, try to infer type for LHS, else use any
28
+ if ( token . parent . parent . kind === SyntaxKind . BinaryExpression )
29
+ {
30
+ const binaryExpression = token . parent . parent as BinaryExpression ;
31
+ binaryExpression . operatorToken ;
32
+
33
+ const type = checker . getTypeAtLocation ( binaryExpression . right ) ;
34
+ typeString = checker . typeToString ( type ) ;
35
+ }
36
+
37
+ const classDeclaration = getContainingClass ( token ) ;
38
+ const startPos = classDeclaration . members . pos ;
39
+ return [ {
40
+ description : getLocaleSpecificMessage ( Diagnostics . Implement_inherited_abstract_class ) ,
41
+ changes : [ {
42
+ fileName : sourceFile . fileName ,
43
+ textChanges : [ {
44
+ span : { start : startPos , length : 0 } ,
45
+ newText : `${ token . getFullText ( sourceFile ) } : ${ typeString } ;`
46
+ } ]
47
+ } ]
48
+ } ] ;
49
+ }
50
+
51
+
52
+
53
+
54
+ // x needs to be a `this` construct. ie
55
+ // this.<thing>.
56
+ // Want to infer type of x when possible. ie:
57
+ // * assignment,
58
+ // * function call argument: foo<T>(this.x) where foo(x: SomeType<T>)
59
+ // * expression with a type assertion: this.x as MyFavoriteType
60
+ // * access expression: this.x.push("asdf") ... probably an array?
61
+ // *
62
+ // What if there are multiple usages of this.x? Create intersection over all usages?
63
+
64
+ // needs to be in a class
65
+ // inferred type might be error. then add any.
66
+ // either make indexable of the inferred type
67
+ // add named member of the inferred type.
68
+ }
69
+
70
+ // // class C {
71
+ // // constructor() {
72
+ // // this.x = 1;
73
+ // // }
74
+ // // }
0 commit comments