// https://github.com/TypeStrong/typedoc-default-themes/blob/master/src/default/partials/member.signature.body.hbs import { Fragment } from 'react' import type { JSONOutput, Models } from 'typedoc'; import { useMinimalLayout } from '../hooks/useMinimalLayout'; import type { TSDSignatureReflection } from '../types'; import { Comment, hasComment } from './Comment'; import { CommentBadges, isCommentWithModifiers } from './CommentBadges'; import { DefaultValue } from './DefaultValue'; import { Flags } from './Flags'; import { hasSources, MemberSources } from './MemberSources'; import { Parameter } from './Parameter'; import { extractDeclarationFromType, Type } from './Type'; import { TypeParameters } from './TypeParameters'; export function hasSigBody( sig: TSDSignatureReflection | undefined, minimal: boolean, hideSources: boolean = false, ) { if (!sig) { return false; } return ( (!hideSources && hasSources(sig)) || hasComment(sig.comment) || (sig.typeParameter && sig.typeParameter.length > 0) || (!minimal && sig.parameters && sig.parameters.length > 0) || (!minimal && sig.type) ); } export interface MemberSignatureBodyProps { hideSources?: boolean; sig: TSDSignatureReflection; } function intoReturnComment(comment?: JSONOutput.Comment): JSONOutput.Comment | undefined { if (comment?.blockTags) { const tags = comment.blockTags.map((tag) => tag.tag); if (tags.includes('@returns')) { const index = tags.indexOf('@returns'); return { summary: comment.blockTags[index].content, }; } } return undefined; } const HIDE_TAGS = ['@returns', '@param']; // eslint-disable-next-line complexity export function MemberSignatureBody({ hideSources, sig }: MemberSignatureBodyProps) { const minimal = useMinimalLayout(); const showTypes = sig.typeParameter && sig.typeParameter.length > 0; const showParams = !minimal && sig.parameters && sig.parameters.length > 0; const showReturn = !minimal && sig.type; return ( <> {!hideSources && } {isCommentWithModifiers(sig.comment) && } {hasComment(sig.comment) && (showTypes || showParams || showReturn) && (
)} {showTypes && ( <>

Type parameters

)} {showParams && ( <>

Parameters

    {sig.parameters?.map((param) => (
  • {param.flags?.isRest && ...} {`${param.name}: `}
  • {param.type?.type === 'reflection' && (
      {param.type.declaration?.children?.map((reflectionChild) => (
    • {reflectionChild.flags?.isRest && ...} {`${reflectionChild.name}: `}
    • ))}
    )} {param.type?.type === 'union' && ( (param.type as unknown as Models.UnionType).types.filter( (unionType) => unionType.type === 'reflection').map( (unionReflectionType) => (
      {unionReflectionType.declaration?.children?.map((unionChild) => (
    • {unionChild.flags?.isRest && ...} {`${unionChild.name}: `}
    • ))}
    )) )}
    ))}
)} {showReturn && ( <>

Returns

)} ); }