TypeScript: Support showing optional properties on TypeTable

This commit is contained in:
Fuma Nama
2025-02-25 16:46:52 +08:00
parent 0f59dfc8f5
commit 7608f4e653
4 changed files with 15 additions and 1 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'fumadocs-typescript': patch
'fumadocs-ui': patch
---
Support showing optional properties on TypeTable
+2
View File
@@ -18,6 +18,7 @@ export interface DocEntry {
description: string;
type: string;
tags: Record<string, string>;
required: boolean;
}
interface EntryContext {
@@ -160,6 +161,7 @@ function getDocEntry(
),
tags,
type: typeName,
required: !prop.isOptional(),
};
transform?.call(context, entry, subType, prop);
@@ -109,6 +109,7 @@ export async function AutoTypeTable({
type: entry.type,
description: await renderMarkdown(entry.description),
default: entry.tags.default || entry.tags.defaultValue,
required: entry.required,
},
] as const,
);
+6 -1
View File
@@ -36,6 +36,8 @@ interface ObjectType {
*/
typeDescriptionLink?: string;
default?: string;
required?: boolean;
}
const field = cva('inline-flex flex-row items-center gap-1');
@@ -64,7 +66,10 @@ export function TypeTable({ type }: { type: Record<string, ObjectType> }) {
<tr key={key}>
<td>
<div className={field()}>
<code className={cn(code({ color: 'primary' }))}>{key}</code>
<code className={cn(code({ color: 'primary' }))}>
{key}
{!value.required && '?'}
</code>
{value.description ? <Info>{value.description}</Info> : null}
</div>
</td>