@@ -271,22 +271,31 @@ export function parseFromProgram(
271
271
const declarations = symbol . getDeclarations ( ) ;
272
272
const declaration = declarations && declarations [ 0 ] ;
273
273
274
- // TypeChecker keeps the name for { a: React.ElementType } but not
275
- // { a?: React.ElementType } can get around this by not using the typechecker
274
+ // TypeChecker keeps the name for
275
+ // { a: React.ElementType, b: React.ReactElement | boolean }
276
+ // but not
277
+ // { a?: React.ElementType, b: React.ReactElement }
278
+ // get around this by not using the TypeChecker
276
279
if (
277
280
declaration &&
278
281
ts . isPropertySignature ( declaration ) &&
279
282
declaration . type &&
280
283
ts . isTypeReferenceNode ( declaration . type )
281
284
) {
282
285
const name = declaration . type . typeName . getText ( ) ;
283
- if ( name === 'React.ElementType' || name === 'React.ComponentType' ) {
286
+ if (
287
+ name === 'React.ElementType' ||
288
+ name === 'React.ComponentType' ||
289
+ name === 'React.ReactElement'
290
+ ) {
291
+ const elementNode = t . elementNode (
292
+ name === 'React.ReactElement' ? 'element' : 'elementType' ,
293
+ ) ;
294
+
284
295
return t . propTypeNode (
285
296
symbol . getName ( ) ,
286
297
getDocumentation ( symbol ) ,
287
- declaration . questionToken
288
- ? t . unionNode ( [ t . undefinedNode ( ) , t . elementNode ( 'elementType' ) ] )
289
- : t . elementNode ( 'elementType' ) ,
298
+ declaration . questionToken ? t . unionNode ( [ t . undefinedNode ( ) , elementNode ] ) : elementNode ,
290
299
) ;
291
300
}
292
301
}
0 commit comments