diff --git a/src/client/rsg-components/Argument/ArgumentRenderer.tsx b/src/client/rsg-components/Argument/ArgumentRenderer.tsx index 9cfbcdd1a..f3dfc513d 100644 --- a/src/client/rsg-components/Argument/ArgumentRenderer.tsx +++ b/src/client/rsg-components/Argument/ArgumentRenderer.tsx @@ -15,7 +15,7 @@ export const styles = ({ space }: Rsg.Theme) => ({ }); export interface ArgumentProps { - name: string; + name?: string; type?: any; default?: string; description?: string; @@ -70,7 +70,7 @@ export const ArgumentRenderer: React.FunctionComponent ArgumentRenderer.propTypes = { classes: PropTypes.objectOf(PropTypes.string.isRequired).isRequired, - name: PropTypes.string.isRequired, + name: PropTypes.string, type: PropTypes.object, default: PropTypes.string, description: PropTypes.string, diff --git a/src/loaders/utils/__tests__/getProps.spec.ts b/src/loaders/utils/__tests__/getProps.spec.ts index e08ecf736..9330fe1a2 100644 --- a/src/loaders/utils/__tests__/getProps.spec.ts +++ b/src/loaders/utils/__tests__/getProps.spec.ts @@ -225,6 +225,40 @@ it("should not crash when using doctrine to parse a default prop that isn't in t expect(result).toMatchSnapshot(); }); +it('should not crash when using doctrine to parse a return method that does not have type in it', () => { + const result = getProps( + { + displayName: 'Button', + methods: [ + { + docblock: ` +Public Method + +@public +@returns {Boolean} return a Boolean Value +`, + returns: { + description: 'return a Boolean Value', + type: { name: 'boolean' }, + }, + }, + ] as any, + }, + __filename + ); + + // @ts-ignore + expect(result.methods[0].returns).toEqual( + expect.objectContaining({ + description: 'return a Boolean Value', + type: { + name: 'boolean', + type: 'NameExpression', + }, + }) + ); +}); + it('should guess a displayName for components that react-docgen was not able to recognize', () => { const result = getProps( { diff --git a/src/loaders/utils/getProps.ts b/src/loaders/utils/getProps.ts index 16900576d..c83e915b2 100644 --- a/src/loaders/utils/getProps.ts +++ b/src/loaders/utils/getProps.ts @@ -94,7 +94,15 @@ export default function getProps(doc: DocumentationObject, filepath?: string): R allTags as TagProps, JS_DOC_METHOD_RETURN_TAG_SYNONYMS ) as TagParamObject[]; - const returns = method.returns || returnTags[0]; + const returns = method.returns + ? { + ...method.returns, + type: { + type: 'NameExpression', + ...method.returns.type, + }, + } + : returnTags[0]; if (returns) { method.returns = returns;