-
Notifications
You must be signed in to change notification settings - Fork 486
TypeScript support #1234
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
TypeScript support #1234
Conversation
I have changed interfaces to use members instead of properties. This allows interfaces to work more like classes, and support annotations for method members, etc. whereas properties were quite limited. This should fix #742 as well. I left type aliases the same (as records with properties), and that seems to make sense to me since interfaces are more often used to describe a class whereas types are more similar to type definitions and might be inlined into docs (e.g. as parameter types). |
Ok, I think this is pretty much ready for review! I added The one major missing feature is generics. There is the |
Amazing! I'm at ye olde day job right now, but I'll take a look at this tonight. |
Rebased and merged in #1236! For folks using documentation.js 'off-the-shelf', noting that this won't immediately show some new features like 'implements' in Markdown or the HTML mode - that's a TODO. But - TypeScript! Thanks @devongovett! |
Awesome, thanks for reviewing such a large PR so quickly! |
Should this work seamlessly if I run |
Please open new issues if you have questions or bugs to report - this is the PR for the feature. |
Thank you for the fantastic work! Unfortunately,
|
Related: #282.
This PR adds TypeScript support to documentationjs, using Babel 7's TypeScript parsing support. This is enabled automatically when a file with a
.ts
or.tsx
extension is seen. Similar to the Flow support, TypeScript annotations are converted to Doctrine compatible values. A wrapper function to handle all Babel-parsed type annotations and convert to Doctrine was added for this.In addition to converting types, inference was added for most TypeScript constructs including access modifiers, abstract classes, getters/setters, function/method params and return types, type alias and interface properties, etc.
There are a few advanced constructs in TypeScript that cannot be directly converted to Doctrine types. I'm not really sure what to do about them:
Perhaps we can start with basic support, and figure out how to get support for these in after the initial implementation is complete. Some of these also have Flow equivalents which are already unhandled by documentationjs.
Full list of TypeScript AST nodes (from babel) is below. Some of them can still be added, others like the above listed categories will be more challenging due to limitations of Doctrine, and others may not be necessary for a documentation generator to support.
Additional JSDoc tags with equivalents in TypeScript (and Flow) that are not yet supported:
@implements
@enum