@@ -248,11 +248,30 @@ export function parseFromProgram(
248
248
249
249
function checkSymbol ( symbol : ts . Symbol , typeStack : number [ ] ) : t . PropTypeNode {
250
250
const declarations = symbol . getDeclarations ( ) ;
251
+ const declaration = declarations && declarations [ 0 ] ;
251
252
252
- const type = declarations
253
+ // TypeChecker keeps the name for { a: React.ElementType } but not
254
+ // { a?: React.ElementType } can get around this by not using the typechecker
255
+ if (
256
+ declaration &&
257
+ ts . isPropertySignature ( declaration ) &&
258
+ declaration . type &&
259
+ ts . isTypeReferenceNode ( declaration . type ) &&
260
+ declaration . type . typeName . getText ( ) === 'React.ElementType'
261
+ ) {
262
+ return t . propTypeNode (
263
+ symbol . getName ( ) ,
264
+ getDocumentation ( symbol ) ,
265
+ declaration . questionToken
266
+ ? t . unionNode ( [ t . undefinedNode ( ) , t . elementNode ( 'elementType' ) ] )
267
+ : t . elementNode ( 'elementType' ) ,
268
+ ) ;
269
+ }
270
+
271
+ const type = declaration
253
272
? // The proptypes aren't detailed enough that we need all the different combinations
254
273
// so we just pick the first and ignore the rest
255
- checker . getTypeOfSymbolAtLocation ( symbol , declarations [ 0 ] )
274
+ checker . getTypeOfSymbolAtLocation ( symbol , declaration )
256
275
: // The properties of Record<..., ...> don't have a declaration, but the symbol has a type property
257
276
( ( symbol as any ) . type as ts . Type ) ;
258
277
0 commit comments