orfium-ictinus icon indicating copy to clipboard operation
orfium-ictinus copied to clipboard

Display or link nested types/interfaces

Open tentascoding opened this issue 3 years ago • 3 comments

It would be nice to have some way to display nested types or link them.

Example:

Clicky clicky to Row or ExtendedColumn should display the nested type or redirect to a page for this type or something. image

After investigating on how to do this, I found these issues:

https://github.com/storybookjs/storybook/issues/13459 https://github.com/storybookjs/storybook/issues/7944 https://github.com/storybookjs/storybook/issues/15008 https://github.com/storybookjs/storybook/issues/13459

If any of these get resolve then Bob's your uncle.

tentascoding avatar Jan 12 '22 10:01 tentascoding

I read in the related issues that the holdup is react-docgen-typescript? May I propose a simpler solution? Extracting the details of interfaces in any given TypeScript source file is pretty straightforward....

const ts = require("typescript");

export const describeInterfaces = (filePath) => {
    const program = ts.createProgram([ filePath ], {
        allowJs: true
    });
    const sourceFile = program.getSourceFile(filePath);
    const typeChecker = program.getTypeChecker();
    ts.forEachChild(sourceFile, node => {
        if (node.kind !== ts.SyntaxKind.InterfaceDeclaration) {
            return;
        }
        const interfaceName = node.name.escapedText;
        console.log(interfaceName);
        node.members.forEach(member => {
            const memberName = member.name.escapedText;
            const memberType = typeChecker.getTypeAtLocation(member.type);
            const memberTypeName = typeChecker.typeToString(memberType);
            console.log("\t" + memberName + " : " + memberTypeName);
        })
    });
};

A DocBlock that provided a capability like this would be awesome....

mrose-acertus avatar Mar 27 '22 02:03 mrose-acertus

This would be amazing and super useful!

dcantu96 avatar May 03 '22 22:05 dcantu96

I really need this!

Dina-Lai avatar Sep 05 '23 08:09 Dina-Lai