@@ -49,7 +49,7 @@ namespace ts.codefix {
49
49
if ( ! isIndexSignatureParameterName ( token ) ) return undefined ;
50
50
51
51
const indexSignature = < IndexSignatureDeclaration > token . parent . parent ;
52
- const container : FixableDeclaration = isInterfaceDeclaration ( indexSignature . parent ) ? indexSignature . parent : < TypeAliasDeclaration > indexSignature . parent . parent ;
52
+ const container = isInterfaceDeclaration ( indexSignature . parent ) ? indexSignature . parent : < TypeAliasDeclaration > indexSignature . parent . parent ;
53
53
const members = isInterfaceDeclaration ( container ) ? container . members : ( < TypeLiteralNode > container . type ) . members ;
54
54
const otherMembers = filter ( members , member => ! isIndexSignatureDeclaration ( member ) ) ;
55
55
const parameter = first ( indexSignature . parameters ) ;
@@ -63,21 +63,33 @@ namespace ts.codefix {
63
63
} ;
64
64
}
65
65
66
+ function getInterfaceHeritageClauses ( declaration : FixableDeclaration ) : NodeArray < ExpressionWithTypeArguments > | undefined {
67
+ if ( ! isInterfaceDeclaration ( declaration ) ) return undefined ;
68
+
69
+ const heritageClause = getHeritageClause ( declaration . heritageClauses , SyntaxKind . ExtendsKeyword ) ;
70
+ return heritageClause && heritageClause . types ;
71
+ }
72
+
66
73
function createTypeAliasFromInterface ( indexSignature : IndexSignatureDeclaration , declaration : FixableDeclaration , otherMembers : ReadonlyArray < TypeElement > , parameterName : Identifier , parameterType : TypeNode ) {
67
- const mappedIntersectionType : TypeNode [ ] = [
68
- createMappedTypeNode (
69
- hasReadonlyModifier ( indexSignature ) ? createModifier ( SyntaxKind . ReadonlyKeyword ) : undefined ,
70
- createTypeParameterDeclaration ( parameterName , parameterType ) ,
71
- indexSignature . questionToken ,
72
- indexSignature . type )
73
- ] ;
74
+ const heritageClauses = getInterfaceHeritageClauses ( declaration ) ;
75
+ const mappedTypeParameter = createTypeParameterDeclaration ( parameterName , parameterType ) ;
76
+ const mappedIntersectionType = createMappedTypeNode (
77
+ hasReadonlyModifier ( indexSignature ) ? createModifier ( SyntaxKind . ReadonlyKeyword ) : undefined ,
78
+ mappedTypeParameter ,
79
+ indexSignature . questionToken ,
80
+ indexSignature . type ) ;
74
81
75
82
return createTypeAliasDeclaration (
76
83
declaration . decorators ,
77
84
declaration . modifiers ,
78
85
declaration . name ,
79
86
declaration . typeParameters ,
80
- createIntersectionTypeNode ( append ( mappedIntersectionType , otherMembers . length ? createTypeLiteralNode ( otherMembers ) : undefined ) )
87
+ createIntersectionTypeNode (
88
+ concatenate (
89
+ heritageClauses ,
90
+ append < TypeNode > ( [ mappedIntersectionType ] , otherMembers . length ? createTypeLiteralNode ( otherMembers ) : undefined )
91
+ )
92
+ )
81
93
) ;
82
94
}
83
95
0 commit comments