diff --git a/src/utils/__tests__/propTypeInfo.js b/src/utils/__tests__/propTypeInfo.js index e3cb621e0..38b036cb8 100644 --- a/src/utils/__tests__/propTypeInfo.js +++ b/src/utils/__tests__/propTypeInfo.js @@ -404,4 +404,60 @@ describe('getTypeMeta', () => { }, }); }); + + test('returns nested type info for union types', () => { + const propType = createPropType('oneOfType', [ + [ + createPropType('string'), + createPropType('shape', [ + { + pathname: createPropType('string', undefined, { + docs: { description: 'The name of the path to link to' }, + }), + search: createPropType('string'), + }, + ]), + ], + ]); + + const component = { + propTypes: { + to: propType, + }, + }; + + expect(getTypeMeta('to', propType, { component })).toEqual({ + types: [ + null, + { + types: [ + { + name: 'pathname', + defaultValue: undefined, + description: 'The name of the path to link to', + deprecation: null, + isRequired: false, + type: { + meta: null, + raw: 'string', + name: 'string', + }, + }, + { + name: 'search', + defaultValue: undefined, + description: undefined, + deprecation: null, + isRequired: false, + type: { + meta: null, + raw: 'string', + name: 'string', + }, + }, + ], + }, + ], + }); + }); }); diff --git a/src/utils/propTypeInfo.js b/src/utils/propTypeInfo.js index cc3e30cba..fdaa96532 100644 --- a/src/utils/propTypeInfo.js +++ b/src/utils/propTypeInfo.js @@ -130,6 +130,15 @@ export const getTypeMeta = (name, propType, { component }) => { }, }; } + case 'oneOfType': { + const [types] = getArgs(propType); + + return { + types: types.map((propType) => + getTypeMeta(name, propType, { component }) + ), + }; + } default: return null; }