@@ -23,8 +23,6 @@ namespace ts.codefix {
23
23
* @returns Empty string iff there we can't figure out a representation for `symbol` in `enclosingDeclaration`.
24
24
*/
25
25
function getInsertionForMemberSymbol ( symbol : Symbol , enclosingDeclaration : ClassLikeDeclaration , checker : TypeChecker , newlineChar : string ) : string {
26
- // const name = symbol.getName();
27
- const type = checker . getTypeOfSymbolAtLocation ( symbol , enclosingDeclaration ) ;
28
26
const declarations = symbol . getDeclarations ( ) ;
29
27
if ( ! ( declarations && declarations . length ) ) {
30
28
return "" ;
@@ -34,12 +32,22 @@ namespace ts.codefix {
34
32
const name = declaration . name ? declaration . name . getText ( ) : undefined ;
35
33
const visibility = getVisibilityPrefixWithSpace ( getModifierFlags ( declaration ) ) ;
36
34
35
+ const typeAtNewDeclaration = checker . getTypeOfSymbolAtLocation ( symbol , enclosingDeclaration ) ;
36
+
37
37
switch ( declaration . kind ) {
38
38
case SyntaxKind . GetAccessor :
39
39
case SyntaxKind . SetAccessor :
40
40
case SyntaxKind . PropertySignature :
41
41
case SyntaxKind . PropertyDeclaration :
42
- const typeString = checker . typeToString ( type , enclosingDeclaration , TypeFormatFlags . None ) ;
42
+ let typeString : string | undefined = undefined ;
43
+ const typeAtOldDeclaration = checker . getTypeAtLocation ( declaration ) ;
44
+ if ( ( typeAtOldDeclaration as TypeParameter ) . isThisType ) {
45
+ typeString = "this" ;
46
+ }
47
+ else {
48
+ typeString = checker . typeToString ( typeAtNewDeclaration , enclosingDeclaration , TypeFormatFlags . None ) ;
49
+ }
50
+
43
51
return `${ visibility } ${ name } : ${ typeString } ;${ newlineChar } ` ;
44
52
45
53
case SyntaxKind . MethodSignature :
@@ -51,7 +59,7 @@ namespace ts.codefix {
51
59
// If there is more than one overload but no implementation signature
52
60
// (eg: an abstract method or interface declaration), there is a 1-1
53
61
// correspondence of declarations and signatures.
54
- const signatures = checker . getSignaturesOfType ( type , SignatureKind . Call ) ;
62
+ const signatures = checker . getSignaturesOfType ( typeAtNewDeclaration , SignatureKind . Call ) ;
55
63
if ( ! ( signatures && signatures . length > 0 ) ) {
56
64
return "" ;
57
65
}
0 commit comments