@@ -48,7 +48,7 @@ export function createTypings(moduleName: string|null, programAst: any, options:
48
48
const m = dom . create . module ( moduleName || 'moduleName' ) ;
49
49
50
50
if ( hasReactClass ( ast , reactComponentName ) ) {
51
- m . members . push ( dom . create . importNamed ( 'Component' , reactImport ) ) ;
51
+ m . members . push ( dom . create . importNamed ( reactComponentName || 'Component' , reactImport ) ) ;
52
52
} else {
53
53
tripleSlashDirectives . push ( dom . create . tripleSlashReferenceTypesDirective ( 'react' ) ) ;
54
54
}
@@ -95,19 +95,29 @@ function createExportedTypes(m: dom.ModuleDeclaration, ast: AstQuery, componentN
95
95
}
96
96
97
97
if ( classComponent ) {
98
- const classDecl = dom . create . class ( componentName ) ;
99
- classDecl . baseType = dom . create . interface ( `Component<${ interf . name } , any>` ) ;
100
- classDecl . flags = exportType ;
101
- classDecl . members . push ( dom . create . method ( 'render' , [ ] , dom . create . namedTypeReference ( 'JSX.Element' ) ) ) ;
102
- m . members . push ( classDecl ) ;
98
+ createExportedClassComponent ( m , componentName , reactComponentName , exportType , interf ) ;
103
99
} else {
104
- const funcDelc = dom . create . function ( componentName , propTypes ? [ dom . create . parameter ( 'props' , interf ) ] : [ ] ,
105
- dom . create . namedTypeReference ( 'JSX.Element' ) ) ;
106
- funcDelc . flags = exportType ;
107
- m . members . push ( funcDelc ) ;
100
+ createExportedFunctionalComponent ( m , componentName , propTypes , exportType , interf ) ;
108
101
}
109
102
}
110
103
104
+ function createExportedClassComponent ( m : dom . ModuleDeclaration , componentName : string ,
105
+ reactComponentName : string | undefined , exportType : dom . DeclarationFlags , interf : dom . InterfaceDeclaration ) : void {
106
+ const classDecl = dom . create . class ( componentName ) ;
107
+ classDecl . baseType = dom . create . interface ( `${ reactComponentName || 'Component' } <${ interf . name } , any>` ) ;
108
+ classDecl . flags = exportType ;
109
+ classDecl . members . push ( dom . create . method ( 'render' , [ ] , dom . create . namedTypeReference ( 'JSX.Element' ) ) ) ;
110
+ m . members . push ( classDecl ) ;
111
+ }
112
+
113
+ function createExportedFunctionalComponent ( m : dom . ModuleDeclaration , componentName : string , propTypes : any ,
114
+ exportType : dom . DeclarationFlags , interf : dom . InterfaceDeclaration ) : void {
115
+ const funcDelc = dom . create . function ( componentName , propTypes ? [ dom . create . parameter ( 'props' , interf ) ] : [ ] ,
116
+ dom . create . namedTypeReference ( 'JSX.Element' ) ) ;
117
+ funcDelc . flags = exportType ;
118
+ m . members . push ( funcDelc ) ;
119
+ }
120
+
111
121
function createPropTypeTypings ( interf : dom . InterfaceDeclaration , ast : AstQuery , propTypes : any ,
112
122
importedPropTypes : ImportedPropTypes , options : IOptions ) : void {
113
123
const res = ast . querySubtree ( propTypes , `
@@ -209,7 +219,7 @@ function getReactComponentName(ast: AstQuery): string|undefined {
209
219
/:source StringLiteral[@value == 'react']
210
220
]
211
221
/:specifiers *[
212
- / Identifier[@name == 'Component']
222
+ / Identifier[@name == 'Component'] || / Identifier[@name == 'PureComponent']
213
223
]
214
224
/:local Identifier
215
225
` ) ;
0 commit comments