From b05948bdd5cc0e7d4b8aaf877c01e4d3fa35d9e5 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Sun, 7 Jun 2020 01:17:01 -0700 Subject: [PATCH] feat: Implement meta info for arrayOf types --- src/utils/__tests__/propTypeInfo.js | 18 ++++++++++++++++++ src/utils/propTypeInfo.js | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/utils/__tests__/propTypeInfo.js b/src/utils/__tests__/propTypeInfo.js index 140621b58..e3cb621e0 100644 --- a/src/utils/__tests__/propTypeInfo.js +++ b/src/utils/__tests__/propTypeInfo.js @@ -386,4 +386,22 @@ describe('getTypeMeta', () => { ], }); }); + + test('returns nested type info for arrayOf types', () => { + const propType = createPropType('arrayOf', [createPropType('string')]); + + const component = { + propTypes: { + names: propType, + }, + }; + + expect(getTypeMeta('names', propType, { component })).toEqual({ + itemTypes: { + meta: null, + raw: 'string', + name: 'string', + }, + }); + }); }); diff --git a/src/utils/propTypeInfo.js b/src/utils/propTypeInfo.js index f5048304b..cc3e30cba 100644 --- a/src/utils/propTypeInfo.js +++ b/src/utils/propTypeInfo.js @@ -119,6 +119,17 @@ export const getTypeMeta = (name, propType, { component }) => { ), }; } + case 'arrayOf': { + const [arrayOfPropType] = getArgs(propType); + + return { + itemTypes: { + meta: getTypeMeta(name, arrayOfPropType, { component }), + raw: getRawTypeName(arrayOfPropType), + name: getNormalizedTypeName(arrayOfPropType), + }, + }; + } default: return null; }