Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inaccurate JSON output types #1389

Closed
EndBug opened this issue Nov 1, 2020 · 7 comments
Closed

Inaccurate JSON output types #1389

EndBug opened this issue Nov 1, 2020 · 7 comments
Labels
bug Functionality does not match expectation

Comments

@EndBug
Copy link

EndBug commented Nov 1, 2020

Hi, I'd like to get the data that TypeDoc generates when it parses a project and use it to convert it to a custom documentation format. The only way I could find is to generate a JSON file in a temp directory so that it can be parsed: the problem with that is that there are no typings for it, and so I can't be sure of all the properties it could have. I've tried manually assigning types from the package but they don't always match correctly, and I was ending up putting // @ts-expect-error everywhere...

Does anybody know how can I get this data directly from the package, before it gets converted to JSON?

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Nov 1, 2020

TypeDoc exports a JSONOutput namespace with types for the JSON. The root object is a JSONOutput.ProjectReflection

Alternatively, to avoid writing out to disk in the first place, you could use TypeDoc's API, though be aware that this will be changing somewhat significantly in 0.20.

const TypeDoc = require('typedoc');

const app = new TypeDoc.Application();
app.options.addReader(new TypeDoc.TSConfigReader());
app.options.addReader(new TypeDoc.TypeDocReader());

app.bootstrap({
    tsconfig: 'tsconfig.json',
});

const project = app.convert(app.expandInputFiles(['src']));

if (project) { // Project may not have converted correctly
    const outputDir = 'docs';

    // Rendered docs
    app.generateDocs(project, outputDir);
    // Alternatively generate JSON output
    app.generateJson(project, outputDir + '/documentation.json');
}

@Gerrit0 Gerrit0 added the question Question about functionality label Nov 1, 2020
@EndBug
Copy link
Author

EndBug commented Nov 1, 2020

Hi, thanks for the reply. I've tried using the JSONOutput.ProjectReflection typings, but they don't seem to correctly match the actual output. Here's an example: a class reflection in the generated JSON file has a property named extendedTypes, but the typings don't show it. There are multiple other properties with this problem.
I'm using the Reflection type for those classes, since it's the type you can extract from Exclude<JSONOutput.ProjectReflection['children'], undefined>[number]

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Nov 1, 2020

That's a bug with those typings then, feel free to submit a PR!

@EndBug
Copy link
Author

EndBug commented Nov 2, 2020

Oh, ok, thanks. I'll close the issue for now.

@EndBug EndBug closed this as completed Nov 2, 2020
@EndBug
Copy link
Author

EndBug commented Nov 2, 2020

@Gerrit0 I've found something interesting: JSONOutput.DeclarationReflection contains all the missing properties that I was mentioning. My question now is: shouldn't ProjectReflection automatically use DeclarationReflection for those typings? Do you already know if there's an issue with that, or is it only a bug in the typings?

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Nov 3, 2020

I looked at the schema code again, and there are some very questionable choices for the types there... why is children on Reflection? That ought to live on ContainerReflection... I'll try and take a look at this next weekend.

@Gerrit0 Gerrit0 added this to To do in Version 0.20 via automation Nov 3, 2020
@Gerrit0 Gerrit0 changed the title [Question] Getting the explain data in Node Inaccurate JSON output types Nov 3, 2020
@Gerrit0 Gerrit0 reopened this Nov 3, 2020
Version 0.20 automation moved this from To do to In progress Nov 3, 2020
@Gerrit0 Gerrit0 added bug Functionality does not match expectation and removed question Question about functionality labels Nov 3, 2020
@Gerrit0 Gerrit0 moved this from In progress to To do in Version 0.20 Nov 6, 2020
@Gerrit0 Gerrit0 moved this from To do to In progress in Version 0.20 Nov 25, 2020
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Nov 26, 2020

Well... much later than I wanted to get to it, but I did finally get to it. v0.20.0-beta.13 has the corrected types. There was a cast to any in the generic serializer, which allowed making much of the serialization dynamic.... but essentially impossible to verify with types. This has now been removed.

@Gerrit0 Gerrit0 moved this from In progress to Done in Version 0.20 Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Functionality does not match expectation
Projects
No open projects
Development

No branches or pull requests

2 participants