Skip to content

Support rest types in Syntax section of reference #836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/components/MethodSignature/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ import { CopyCodeButton } from "../CopyCodeButton";

const { params, name, overloads } = Astro.props;

const formatParam = (param: ReferenceParam) =>
param.optional ? `[${param.name}]` : `${param.name}`;
const formatParam = (param: ReferenceParam) => {
let formatted = param.optional ? `[${param.name}]` : `${param.name}`;
if (param.rest) {
formatted = `${param.name}1, ${param.name}2, ..., ${param.name}n`;
}
return formatted;
};

const signatures = params
? [`${name}(${params.map(formatParam).join(", ")})`]
Expand Down
1 change: 1 addition & 0 deletions src/content/reference/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const paramSchema = z.object({
description: z.string().optional(),
type: z.string().optional(),
optional: z.coerce.boolean().optional(),
rest: z.coerce.boolean().optional(),
});

const returnSchema = z.object({
Expand Down
9 changes: 7 additions & 2 deletions src/layouts/ReferenceItemLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ const descriptionParts = description.split(
{entry.data.params &&
entry.data.params.map((param: ReferenceParam) => (
<div class="grid grid-cols-6 gap-gutter-md text-body">
<span class="col-span-1 text-body whitespace-normal break-words overflow-wrap-break-word">{param.name}</span>
<span class="col-span-1 text-body whitespace-normal break-words overflow-wrap-break-word">

{param.rest ? `${param.name}1, ..., ${param.name}n` : param.name}
</span>
<div
class="col-span-5 [&_p]:m-0 [&_p]:inline [&_a]:underline"
>
Expand All @@ -197,7 +200,9 @@ const descriptionParts = description.split(
seenParams[param.name] = true;
return (
<div class="grid grid-cols-6 gap-gutter-md text-body">
<span class="col-span-1">{param.name}</span>
<span class="col-span-1">
{param.rest ? `${param.name}1, ..., ${param.name}n` : param.name}
</span>
<div
class="col-span-5 [&_p]:m-0 [&_p]:inline [&_a]:underline"
>
Expand Down
1 change: 1 addition & 0 deletions types/parsers.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface ReferenceParam {
description: string; // A description of the parameter.
type: string; // The data type of the parameter.
optional?: boolean; // Indicates if the parameter is optional.
rest?: boolean; // Whether or not this is a variadic parameter at the end of the arg list
}

export type ReferenceOverload = {
Expand Down