File tree 1 file changed +14
-8
lines changed
1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -214,6 +214,19 @@ export function parseFromProgram(
214
214
}
215
215
}
216
216
217
+ function isTypeJSXElementLike ( type : ts . Type ) : boolean {
218
+ if ( type . isUnion ( ) ) {
219
+ return type . types . every (
220
+ subType => subType . flags & ts . TypeFlags . Null || isTypeJSXElementLike ( subType ) ,
221
+ ) ;
222
+ } else if ( type . symbol ) {
223
+ const name = checker . getFullyQualifiedName ( type . symbol ) ;
224
+ return name === 'global.JSX.Element' || name === 'React.ReactElement' ;
225
+ }
226
+
227
+ return false ;
228
+ }
229
+
217
230
function parseFunctionComponent ( node : ts . VariableDeclaration | ts . FunctionDeclaration ) {
218
231
if ( ! node . name ) {
219
232
return ;
@@ -228,14 +241,7 @@ export function parseFromProgram(
228
241
. getTypeOfSymbolAtLocation ( symbol , symbol . valueDeclaration )
229
242
. getCallSignatures ( ) [ 0 ] ;
230
243
231
- const rawReturnType = signature . getReturnType ( ) ;
232
- if ( ! rawReturnType . symbol ) {
233
- return ;
234
- }
235
-
236
- const returnType = checker . getFullyQualifiedName ( rawReturnType . symbol ) ;
237
-
238
- if ( returnType !== 'global.JSX.Element' && returnType !== 'React.ReactElement' ) {
244
+ if ( ! isTypeJSXElementLike ( signature . getReturnType ( ) ) ) {
239
245
return ;
240
246
}
241
247
You can’t perform that action at this time.
0 commit comments