Skip to content

Instantly share code, notes, and snippets.

@JessicaSachs
Last active September 12, 2023 22:15
Show Gist options
  • Save JessicaSachs/0dfd3c1343ef1503bad683800d7c420f to your computer and use it in GitHub Desktop.
Save JessicaSachs/0dfd3c1343ef1503bad683800d7c420f to your computer and use it in GitHub Desktop.
Relationships between exported functions and their resolved signatures and return types
// Here's the attempt by a Babel parser to deal with this code https://shorturl.at/clADR
// Totally not related to the proposed schema above.
/**
* All the valid ButtonSizes
*/
export type ButtonSize = "small" | "medium" | "large";
export function MyButton({ size = 'small' }: { size: ButtonSize }) {
const sizes = {
small: "px-1 py-[0.5]",
medium: "px-2 py-1",
large: "px-3 py-2",
};
const button = document.createElement("button");
button.innerText = `I'm a ${size} button`;
button.className = sizes[size];
return button;
}
export function renderButton(): void {
const mySmallButton = MyButton({ size: "small" });
document.body.appendChild(mySmallButton);
}
// Proposed Schema
// Ideally I can build relationships between return types, parameters, and exported functions
const schema = {
types: {
'#/definitions/SomeType': {
id: '#/definitions/SomeType',
file: 'path/to/file.ts',
name: 'SomeType',
type: "object",
description: "Some type description",
jsdoc: {
description: "Some type description",
tags: [
{
tag: "example",
text: "Some example",
},
{
tag: "see",
text: "Some see",
},
],
},
properties: {
foo: {
type: "object",
properties: {
bar: {
type: "string",
},
},
},
bar: {
type: "number",
},
},
}
},
functions: {
"Component2NameById": {
id: "ComponentNameById",
file: 'path/to/file.ts',
name: 'Component Name',
returnType: {
name: "(ButtonProps | ButtonSize)[]",
id: '',
},
params: [
{
name: "param1",
type: "string",
description: "The first parameter",
},
{
name: "param2",
type: "number",
description: "The second parameter",
},
{
name: "param3",
type: "#/definitions/SomeType",
},
],
},
"ComponentNameById": {
id: "ComponentNameById",
file: 'path/to/file.ts',
name: 'Component Name',
returnType: {
name: "HTMLButtonElement",
id: '',
},
params: [
{
name: "param1",
type: "string",
description: "The first parameter",
},
{
name: "param2",
type: "number",
description: "The second parameter",
},
{
name: "param3",
type: "#/definitions/SomeType",
},
],
},
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment