diff --git a/addons/docs/src/lib/docgenUtils.ts b/addons/docs/src/lib/docgenUtils.ts index 90f2f8aee670..8bf6d15bfb26 100644 --- a/addons/docs/src/lib/docgenUtils.ts +++ b/addons/docs/src/lib/docgenUtils.ts @@ -5,7 +5,7 @@ import { getTypeSystemHandler, getPropTypeSystem } from './type-system-handlers' export type PropsExtractor = (component: Component) => PropsTableProps | null; -export type PropDefGetter = (type: Component, section: string) => PropDef[]; +export type PropDefGetter = (component: Component, section: string) => PropDef[]; export const str = (o: any) => { if (!o) { @@ -17,27 +17,24 @@ export const str = (o: any) => { throw new Error(`Description: expected string, got: ${JSON.stringify(o)}`); }; -export const hasDocgen = (obj: any) => !!obj.__docgenInfo; +export const hasDocgen = (component: Component) => !!component.__docgenInfo; -export const hasDocgenSection = (obj: any, section: string) => - obj.__docgenInfo && - obj.__docgenInfo[section] && - Object.keys(obj.__docgenInfo[section]).length > 0; +export const hasDocgenSection = (component: Component, section: string) => + component && + component.__docgenInfo && + component.__docgenInfo[section] && + Object.keys(component.__docgenInfo[section]).length > 0; -export const extractPropsFromDocgen: PropDefGetter = (type, section) => { - const props: Record = {}; - - const docgenInfoProps = type.__docgenInfo[section]; - if (!docgenInfoProps) { +export const extractPropsFromDocgen: PropDefGetter = (component, section) => { + if (!hasDocgenSection(component, section)) { return []; } + const props: Record = {}; + const docgenInfoProps = component.__docgenInfo[section]; const propKeys = Object.keys(docgenInfoProps); - if (propKeys.length === 0) { - return []; - } - // Assuming the props for a given type will all have the same type system. + // Assuming the props for a given component will all have the same type system. const typeSystem = getPropTypeSystem(docgenInfoProps[propKeys[0]]); const typeSystemHandler = getTypeSystemHandler(typeSystem);