.armaan.s.
.armaan.s.5mo ago

Extract TypeScript types as JSON?

I have a Hono server and I want to extract / save the server routes type to either a .d.ts or a .json file. Ideally I would automate it using CLI commands but I can't even manually copy the types out of VSCode because the type get's truncated:
type RoutesType = {
[x: `/google/${string}`]: {
$get: {
input: {};
output: {
token: {
token: string;
expires_in: number;
} | undefined;
grantedScopes: string[] | undefined;
user: {
id?: string | undefined;
email?: string | undefined;
... 5 more ...;
locale?: string | undefined;
} | undefined;
};
outputFormat: "json";
status: StatusCode;
};
};
... 11 more ...;
"/static/*": {
...;
};
}
type RoutesType = {
[x: `/google/${string}`]: {
$get: {
input: {};
output: {
token: {
token: string;
expires_in: number;
} | undefined;
grantedScopes: string[] | undefined;
user: {
id?: string | undefined;
email?: string | undefined;
... 5 more ...;
locale?: string | undefined;
} | undefined;
};
outputFormat: "json";
status: StatusCode;
};
};
... 11 more ...;
"/static/*": {
...;
};
}
When you hover over the type in VSCode, most of the route types are hidden by ellipses. Is there a way to see the full type and is there a way to convert it to JSON, in a format like:
{
"output": {
"token": {
"OR": [
{
"token": "string",
"expires_in": "number",
},
"undefined"
]
}
}
}
{
"output": {
"token": {
"OR": [
{
"token": "string",
"expires_in": "number",
},
"undefined"
]
}
}
}
1 Reply
EthanThatOneKid
EthanThatOneKid5mo ago
The doc subcommand is capable of generating documentation for a given module https://docs.deno.com/runtime/manual/tools/documentation_generator/#json-output

Did you find this page helpful?