-
-
Notifications
You must be signed in to change notification settings - Fork 738
[RFC] Consider extracting toString
functionality to standalone module
#1160
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
Comments
Thanks for taking the time to write this out for discussion. I think factoring out the conversion from a TypeScript project to models into a new module that TypeDoc consumes would be beneficial in forcing us to design an API that is actually usable for consumers. #439 was an attempt at this several years ago, but ended up just getting neglected since there wasn't enough time to get it reviewed + merged. The Right now we offer very little support for consumers of the JSON format. There are several interfaces that describe the resulting type, but no easy way to consume it. This would be a step in the right direction, and the described solution makes sense to me. (not to put a damper on this effort but...) If you want toString functionality, why consume the JSON in the first place? It is fairly straightforward to get a |
@Gerrit0 For my Docusaurus use case, I wasn't able to figure out a way to use the API where it could process the files (server side) and also pass that data to the renderer (client side). The client is also unable to use things like Node's |
Ah, that makes sense. 👍 |
Eventually I want to make it possible to use TypeDoc from a browser, that's so far away, and so low down on the priority, list, however, that it's likely not going to happen... |
Problem
It's not currently possible to use typedoc's type to string rendering alone — you get the CLI, the file/filesystem handling, markdown rendering & syntax highlighting, etc. Extracting string rendering to a separate module/package would enable:
My driving use case is to render types to documentation in Docusaurus v2, which uses React & MDX. While there is an existing plugin for outputting markdown and targeting Docusaurus v2, it doesn't allow using the full power of the React & MDX ecosystems (it just outputs static markdown).
Suggested Solution
I'd be willing to work on this if accepted. I recommend extracting the
toString
methods that currently live in each of typedoc's various type classes into a separate module that can then be used internally as well as exposed to allow the above mentioned features. The new API would act on objects provided as arguments which should allow it to support both the existing functionality and also operate on data such as from typedoc's serialized JSON output.I imagine at a high level that the API could look something like this:
Then the existing classes could likely be refactored to use these by implementing
toString
in the base class instead of overriding it in every subclass:The text was updated successfully, but these errors were encountered: