Skip to content

Commit

Permalink
refactor: isUnion takes a prop type
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 6, 2020
1 parent 1d33f8f commit 110f52b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/utils/propTypeInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const UNION_DELIMITER = '|';
const getArgs = (propType) =>
propType.__reflect__.find(({ args }) => args)?.args;

const isUnion = (typeName) => typeName.includes(UNION_DELIMITER);
const isUnion = (propType) => getRawTypeName(propType) === 'oneOfType';

export const getRawTypeName = (propType) => propType.__reflect__[1].name;

Expand All @@ -25,10 +25,10 @@ export const getNormalizedTypeName = (propType) => {
.join(UNION_DELIMITER);
}
case 'arrayOf': {
const args = getArgs(propType);
const arrayType = getNormalizedTypeName(args[0]);
const [arrayOfPropType] = getArgs(propType);
const typeName = getNormalizedTypeName(arrayOfPropType);

return isUnion(arrayType) ? `(${arrayType})[]` : `${arrayType}[]`;
return isUnion(arrayOfPropType) ? `(${typeName})[]` : `${typeName}[]`;
}
default:
return name;
Expand Down

0 comments on commit 110f52b

Please sign in to comment.