Skip to content

Commit

Permalink
fix: Return type info for union types
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 7, 2020
1 parent 0ad9dbe commit f973f9f
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 77 deletions.
168 changes: 94 additions & 74 deletions src/utils/__tests__/propTypeInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,34 +437,42 @@ describe('getTypeMeta', () => {

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: 'string',
raw: 'string',
meta: null,
},
{
name: 'shape',
raw: 'shape',
meta: {
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',
{
name: 'search',
defaultValue: undefined,
description: undefined,
deprecation: null,
isRequired: false,
type: {
meta: null,
raw: 'string',
name: 'string',
},
},
},
],
],
},
},
],
});
Expand Down Expand Up @@ -542,64 +550,76 @@ describe('getTypeMeta', () => {

expect(getTypeMeta('crazy', propType, { component })).toEqual({
types: [
null,
{
itemTypes: {
meta: {
types: [
{
name: 'name',
defaultValue: undefined,
description: undefined,
deprecation: null,
isRequired: true,
type: {
meta: null,
raw: 'string',
name: 'string',
},
},
{
name: 'onHide',
defaultValue: undefined,
description: undefined,
deprecation: null,
isRequired: false,
type: {
meta: {
returnValue: { type: 'undefined' },
params: [],
meta: null,
raw: 'string',
name: 'string',
},
{
raw: 'arrayOf',
name: 'shape[]',
meta: {
itemTypes: {
meta: {
types: [
{
name: 'name',
defaultValue: undefined,
description: undefined,
deprecation: null,
isRequired: true,
type: {
meta: null,
raw: 'string',
name: 'string',
},
raw: 'func',
name: 'function',
},
},
{
name: 'onHidden',
defaultValue: undefined,
description: undefined,
deprecation: null,
isRequired: false,
deprecation: {
date: 1591519180477,
description: 'Use onHide',
{
name: 'onHide',
defaultValue: undefined,
description: undefined,
deprecation: null,
isRequired: false,
type: {
meta: {
returnValue: { type: 'undefined' },
params: [],
},
raw: 'func',
name: 'function',
},
},
type: {
meta: {
returnValue: { type: 'undefined' },
params: [],
{
name: 'onHidden',
defaultValue: undefined,
description: undefined,
deprecation: null,
isRequired: false,
deprecation: {
date: 1591519180477,
description: 'Use onHide',
},
type: {
meta: {
returnValue: { type: 'undefined' },
params: [],
},
raw: 'func',
name: 'function',
},
raw: 'func',
name: 'function',
},
},
],
],
},
raw: 'shape',
name: 'shape',
},
raw: 'shape',
name: 'shape',
},
},
{ constants: ['Wacky.CRAZY.ONE', 'Wacky.CRAZY.TWO'] },
{
name: 'enum',
raw: 'oneOf',
meta: { constants: ['Wacky.CRAZY.ONE', 'Wacky.CRAZY.TWO'] },
},
],
});
});
Expand Down
8 changes: 5 additions & 3 deletions src/utils/propTypeInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ export const getTypeMeta = (name, propType, { component }) => {
const [types] = getArgs(propType);

return {
types: types.map((propType) =>
getTypeMeta(name, propType, { component })
),
types: types.map((propType) => ({
name: getNormalizedTypeName(propType),
raw: getRawTypeName(propType),
meta: getTypeMeta(name, propType, { component }),
})),
};
}
default:
Expand Down

0 comments on commit f973f9f

Please sign in to comment.