diff --git a/code/lib/docs-tools/src/argTypes/convert/flow/convert.ts b/code/lib/docs-tools/src/argTypes/convert/flow/convert.ts index 5886babe7301..b950be171bee 100644 --- a/code/lib/docs-tools/src/argTypes/convert/flow/convert.ts +++ b/code/lib/docs-tools/src/argTypes/convert/flow/convert.ts @@ -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 }; } diff --git a/code/lib/docs-tools/src/argTypes/convert/typescript/convert.ts b/code/lib/docs-tools/src/argTypes/convert/typescript/convert.ts index 2bf1fe65e552..95436dfcb567 100644 --- a/code/lib/docs-tools/src/argTypes/convert/typescript/convert.ts +++ b/code/lib/docs-tools/src/argTypes/convert/typescript/convert.ts @@ -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 }; } diff --git a/code/lib/docs-tools/src/argTypes/convert/typescript/types.ts b/code/lib/docs-tools/src/argTypes/convert/typescript/types.ts index aed18f3f4160..79df2e812c00 100644 --- a/code/lib/docs-tools/src/argTypes/convert/typescript/types.ts +++ b/code/lib/docs-tools/src/argTypes/convert/typescript/types.ts @@ -9,7 +9,7 @@ type TSArgType = TSType; type TSCombinationType = TSBaseType & { name: 'union' | 'intersection'; - elements: TSType[]; + elements?: TSType[]; }; type TSFuncSigType = TSBaseType & {