mirror of
https://github.com/discordjs/discord.js.git
synced 2024-07-16 03:07:35 +12:00
feat(website): type parameters on methods and overloads (#9998)
* feat(website): type parameters on methods and overloads * refactor: add collapsible parameter list
This commit is contained in:
parent
179af387d0
commit
1ec2901f56
|
@ -1,11 +1,13 @@
|
|||
import type {
|
||||
ApiDeclaredItem,
|
||||
ApiItemContainerMixin,
|
||||
ApiMethod,
|
||||
ApiMethodSignature,
|
||||
import {
|
||||
ApiItemKind,
|
||||
type ApiDeclaredItem,
|
||||
type ApiItemContainerMixin,
|
||||
type ApiMethod,
|
||||
type ApiMethodSignature,
|
||||
} from '@discordjs/api-extractor-model';
|
||||
import { ParameterSection } from '~/components/documentation/section/ParametersSection';
|
||||
import { TypeParameterSection } from '~/components/documentation/section/TypeParametersSection';
|
||||
import { InheritanceText } from '../../InheritanceText';
|
||||
import { ParameterTable } from '../../ParameterTable';
|
||||
import { TSDoc } from '../../documentation/tsdoc/TSDoc';
|
||||
|
||||
export interface MethodDocumentationProps {
|
||||
|
@ -15,15 +17,22 @@ export interface MethodDocumentationProps {
|
|||
|
||||
export function MethodDocumentation({ method, inheritedFrom }: MethodDocumentationProps) {
|
||||
const parent = method.parent as ApiDeclaredItem;
|
||||
const firstOverload = method
|
||||
.getMergedSiblings()
|
||||
.find((meth): meth is ApiMethod => meth.kind === ApiItemKind.Method && (meth as ApiMethod).overloadIndex === 1)
|
||||
?.tsdocComment;
|
||||
|
||||
if (!(method.tsdocComment?.summarySection || method.parameters.length > 0)) {
|
||||
if (!(method.tsdocComment?.summarySection || firstOverload?.summarySection || method.parameters.length > 0)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mb-4 w-full flex flex-col gap-4">
|
||||
{method.tsdocComment ? <TSDoc item={method} tsdoc={method.tsdocComment} /> : null}
|
||||
{method.parameters.length ? <ParameterTable item={method} /> : null}
|
||||
{method.tsdocComment || firstOverload ? (
|
||||
<TSDoc item={method} tsdoc={method.tsdocComment ?? firstOverload!} />
|
||||
) : null}
|
||||
{method.typeParameters.length ? <TypeParameterSection item={method} /> : null}
|
||||
{method.parameters.length ? <ParameterSection item={method} /> : null}
|
||||
{inheritedFrom && parent ? <InheritanceText parent={inheritedFrom} /> : null}
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
import type {
|
||||
ApiDocumentedItem,
|
||||
ApiEntryPoint,
|
||||
ApiModel,
|
||||
ApiParameterListMixin,
|
||||
Excerpt,
|
||||
} from '@discordjs/api-extractor-model';
|
||||
import type { ApiDocumentedItem, ApiEntryPoint, ApiModel, Excerpt } from '@discordjs/api-extractor-model';
|
||||
import { ApiParameterListMixin } from '@discordjs/api-extractor-model';
|
||||
import type { DocSection } from '@microsoft/tsdoc';
|
||||
import { resolvePackageName } from './resolvePackageName';
|
||||
|
||||
|
@ -41,7 +36,14 @@ interface ResolvedParameter {
|
|||
*/
|
||||
export function resolveParameters(item: ApiDocumentedItem & ApiParameterListMixin): ResolvedParameter[] {
|
||||
return item.parameters.map((param, idx) => {
|
||||
const tsdocAnalog = item.tsdocComment?.params.blocks[idx];
|
||||
const tsdocAnalog =
|
||||
item.tsdocComment?.params.blocks[idx] ??
|
||||
item
|
||||
.getMergedSiblings()
|
||||
.find(
|
||||
(paramList): paramList is ApiDocumentedItem & ApiParameterListMixin =>
|
||||
ApiParameterListMixin.isBaseClassOf(paramList) && paramList.overloadIndex === 1,
|
||||
)?.tsdocComment?.params.blocks[idx];
|
||||
|
||||
return {
|
||||
name: param.tsdocParamBlock?.parameterName ?? tsdocAnalog?.parameterName ?? param.name,
|
||||
|
|
Loading…
Reference in a new issue