Skip to content

Commit adfcca4

Browse files
committed
fix(parser): handle prop of type ReactElement
1 parent 3f5c0c9 commit adfcca4

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/parser.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -271,22 +271,31 @@ export function parseFromProgram(
271271
const declarations = symbol.getDeclarations();
272272
const declaration = declarations && declarations[0];
273273

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
276279
if (
277280
declaration &&
278281
ts.isPropertySignature(declaration) &&
279282
declaration.type &&
280283
ts.isTypeReferenceNode(declaration.type)
281284
) {
282285
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+
284295
return t.propTypeNode(
285296
symbol.getName(),
286297
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,
290299
);
291300
}
292301
}

0 commit comments

Comments
 (0)