feat: more visibly annotate optionals

This commit is contained in:
iCrawl
2022-08-17 22:16:22 +02:00
parent 7701331b1c
commit 20680efbc9
2 changed files with 4 additions and 3 deletions

View File

@@ -39,6 +39,7 @@ export function CodeListing({
{optional ? <Badge variant="filled">Optional</Badge> : null} {optional ? <Badge variant="filled">Optional</Badge> : null}
<Title order={4} className="font-mono"> <Title order={4} className="font-mono">
{name} {name}
{optional ? '?' : ''}
</Title> </Title>
<Title order={4}>{separator}</Title> <Title order={4}>{separator}</Title>
<Title order={4} className="font-mono break-all"> <Title order={4} className="font-mono break-all">

View File

@@ -9,12 +9,12 @@ import { Visibility } from '~/DocModel/Visibility';
type MethodResolvable = ReturnType<DocMethod['toJSON']> | ReturnType<DocMethodSignature['toJSON']>; type MethodResolvable = ReturnType<DocMethod['toJSON']> | ReturnType<DocMethodSignature['toJSON']>;
function getShorthandName(data: MethodResolvable) { function getShorthandName(data: MethodResolvable) {
return `${data.name}(${data.parameters.reduce((prev, cur, index) => { return `${data.name}${data.optional ? '?' : ''}(${data.parameters.reduce((prev, cur, index) => {
if (index === 0) { if (index === 0) {
return `${prev}${cur.name}`; return `${prev}${cur.isOptional ? `[${cur.name}]` : cur.name}`;
} }
return `${prev}, ${cur.name}`; return `${prev}, ${cur.isOptional ? `[${cur.name}]` : cur.name}`;
}, '')})`; }, '')})`;
} }