Skip to content

Commit

Permalink
Merge pull request #26639 from storybookjs/kasper/empty-union
Browse files Browse the repository at this point in the history
React-Docgen: Make sure to be able to handle empty unions
(cherry picked from commit 889cfdf)
  • Loading branch information
kasperpeulen authored and storybook-bot committed Mar 26, 2024
1 parent 5711b12 commit 366d113
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions code/lib/docs-tools/src/argTypes/convert/flow/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export const convert = (type: FlowType): SBType | void => {
case 'signature':
return { ...base, ...convertSig(type) };
case 'union':
if (type.elements.every(isLiteral)) {
return { ...base, name: 'enum', value: type.elements.map(toEnumOption) };
if (type.elements?.every(isLiteral)) {
return { ...base, name: 'enum', value: type.elements?.map(toEnumOption) };
}
return { ...base, name, value: type.elements.map(convert) };
return { ...base, name, value: type.elements?.map(convert) };

case 'intersection':
return { ...base, name, value: type.elements.map(convert) };
return { ...base, name, value: type.elements?.map(convert) };
default:
return { ...base, name: 'other', value: name };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ export const convert = (type: TSType): SBType | void => {
return { ...base, ...convertSig(type) };
case 'union':
let result;
if (type.elements.every((element) => element.name === 'literal')) {
if (type.elements?.every((element) => element.name === 'literal')) {
result = {
...base,
name: 'enum',
// @ts-expect-error fix types
value: type.elements.map((v) => parseLiteral(v.value)),
value: type.elements?.map((v) => parseLiteral(v.value)),
};
} else {
result = { ...base, name, value: type.elements.map(convert) };
result = { ...base, name, value: type.elements?.map(convert) };
}
return result;
case 'intersection':
return { ...base, name, value: type.elements.map(convert) };
return { ...base, name, value: type.elements?.map(convert) };
default:
return { ...base, name: 'other', value: name };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type TSArgType = TSType;

type TSCombinationType = TSBaseType & {
name: 'union' | 'intersection';
elements: TSType[];
elements?: TSType[];
};

type TSFuncSigType = TSBaseType & {
Expand Down

0 comments on commit 366d113

Please sign in to comment.