Skip to content

Commit

Permalink
Addon-docs: Error on non-string description (#7650)
Browse files Browse the repository at this point in the history
Addon-docs: Error on non-string description
  • Loading branch information
shilman authored Aug 1, 2019
2 parents 8f591bd + a2bd784 commit bf876ce
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions addons/docs/src/blocks/Description.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@ interface DescriptionProps {
markdown?: string;
}

const str = (o: any) => {
if (!o) {
return '';
}
if (typeof o === 'string') {
return o as string;
}
throw new Error(`Description: expected string, got: ${JSON.stringify(o)}`);
};

const getNotes = (notes?: Notes) =>
(notes && (typeof notes === 'string' ? notes : notes.markdown || notes.text)) || '';
notes && (typeof notes === 'string' ? notes : str(notes.markdown) || str(notes.text));

const getInfo = (info?: Info) => (info && (typeof info === 'string' ? info : info.text)) || '';
const getInfo = (info?: Info) => info && (typeof info === 'string' ? info : str(info.text));

const getDocgen = (component?: Component) =>
(component && component.__docgenInfo && component.__docgenInfo.description) || '';
component && component.__docgenInfo && str(component.__docgenInfo.description);

export const getDescriptionProps = (
{ of, type, markdown }: DescriptionProps,
Expand All @@ -50,7 +60,7 @@ export const getDescriptionProps = (
markdown: `
${getNotes(notes) || getInfo(info) || ''}
${getDocgen(target)}
${getDocgen(target) || ''}
`.trim(),
};
}
Expand Down

1 comment on commit bf876ce

@vercel
Copy link

@vercel vercel bot commented on bf876ce Aug 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.