Skip to content

Commit

Permalink
ensure nullable shows
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-support committed Jan 14, 2025
1 parent 69227e2 commit 273df0a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/fern-docs/ui/src/type-shorthand/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export function renderTypeShorthandRoot(
hideOptional = false
): ReactNode {
const unwrapped = unwrapReference(shape, types);
const typeShorthand = renderTypeShorthand(unwrapped.shape, {}, types);
const typeShorthand = renderTypeShorthand(
unwrapped.shape,
{ nullable: unwrapped.isNullable },
types
);
return (
<span className="fern-api-property-meta">
<span>{typeShorthand}</span>
Expand Down Expand Up @@ -155,14 +159,18 @@ function toPrimitiveTypeLabelsString({

export function renderTypeShorthand(
shape: TypeShapeOrReference,
{ plural = false, withArticle = false }: TypeShorthandOptions = {
{
plural = false,
withArticle = false,
nullable = false,
}: TypeShorthandOptions = {
plural: false,
withArticle: false,
nullable: false,
},
types: Record<string, TypeDefinition>
): string {
const unwrapped = unwrapReference(shape, types);

const maybeWithArticle = (article: string, stringWithoutArticle: string) =>
withArticle ? `${article} ${stringWithoutArticle}` : stringWithoutArticle;

Expand All @@ -174,7 +182,7 @@ export function renderTypeShorthand(
return `${maybeWithArticle("an", "optional")} ${renderTypeShorthand(unwrapped.shape, { plural }, types)}`;
}

return visitDiscriminatedUnion(unwrapped.shape)._visit({
const result = visitDiscriminatedUnion(unwrapped.shape)._visit({
// primitives
primitive: (primitive) =>
visitDiscriminatedUnion(primitive.value, "type")._visit({
Expand Down Expand Up @@ -247,4 +255,6 @@ export function renderTypeShorthand(
unknown: (value) => value.displayName ?? "any",
_other: () => "<unknown>",
});

return nullable ? `${result} or null` : result;
}

0 comments on commit 273df0a

Please sign in to comment.