Skip to content

Commit

Permalink
fix: 馃悰 Fixed and polished processing
Browse files Browse the repository at this point in the history
  • Loading branch information
prc5 committed May 19, 2023
1 parent 8c33ed8 commit f45c02b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/docs/pages/components/returns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PagePropsType } from "../../../types/page.types";
import { getTag } from "../utils/tags.utils";
import { getTypePresentation } from "../utils/types.utils";
import { Code } from "./code";
import { NonParsing } from "./non-parsing";
// import { NonParsing } from "./non-parsing";

export const Returns: React.FC<
PagePropsType<JSONOutput.DeclarationReflection | JSONOutput.SignatureReflection>
Expand All @@ -19,13 +19,14 @@ export const Returns: React.FC<

return (
<div className="api-docs__returns">
{returnTag?.description && (
{/* Cause bugs because of postprocessing cannot correctly parse code block */}
{/* {returnTag?.description && (
<NonParsing>
{"\n"}
{returnTag.description}
{"\n"}
</NonParsing>
)}
)} */}
{!disableReturn && <Code>{getTypePresentation(reflection, reflectionsTree)}</Code>}
</div>
);
Expand Down
14 changes: 12 additions & 2 deletions src/docs/pages/utils/types.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ export const getTypeValue = (
return reflection;
};

const stringify = (value: unknown) => {
if (value === null) {
return String(value);
}
if (typeof value === "object") {
return JSON.stringify(value);
}
return String(value);
};

export const getType = (
reflection: JSONOutput.DeclarationReflection | JSONOutput.SomeType | undefined,
reflectionsTree: JSONOutput.ProjectReflection[],
Expand Down Expand Up @@ -293,7 +303,7 @@ export const getType = (
const type = reflection as unknown as JSONOutput.UnionType;

return `${type.types
.map((t) => JSON.stringify(getType(t, reflectionsTree, { deepScan })))
.map((t) => stringify(getType(t, reflectionsTree, { deepScan })))
.join(" | ")}`;
}

Expand All @@ -319,7 +329,7 @@ export const getType = (
(t) => `$\{${getType(t[0], reflectionsTree, { deepScan: false })}}${t[1]}`,
);

return `\`${head}${tail}\``;
return `${head}${tail}`;
}

default: {
Expand Down

0 comments on commit f45c02b

Please sign in to comment.