Skip to content

Generate types from JSDoc#47

Draft
mikaelkaron wants to merge 24 commits into
fergiemcdowall:masterfrom
mikaelkaron:types-from-jsdoc
Draft

Generate types from JSDoc#47
mikaelkaron wants to merge 24 commits into
fergiemcdowall:masterfrom
mikaelkaron:types-from-jsdoc

Conversation

@mikaelkaron

@mikaelkaron mikaelkaron commented Jul 26, 2022

Copy link
Copy Markdown
Contributor

Instead of maintaining separate @types/* it would be nice to have types generated and shipped with the package.

This PR adds support for generating *.d.ts from JSDoc style comments.

@mikaelkaron mikaelkaron marked this pull request as draft July 26, 2022 16:53
@mikaelkaron

Copy link
Copy Markdown
Contributor Author

@fergiemcdowall Is this something you'd be interested in?

At the moment I'm extracting what I can from the docs and code comments where I can find them, but long-term this should be a lot more maintainable (and possibly testable) than a separate @types/* package.

@fergiemcdowall

Copy link
Copy Markdown
Owner

Yes absolutely 👍👍 (I see that level now includes Typescript definitions)

@mikaelkaron

Copy link
Copy Markdown
Contributor Author

For some reason I'm not able to output all the types to:

  • one file in dist
  • separate types dir

So for now I'm just using the default (that works) of outputting the *.d.ts file next to the source.

@fergiemcdowall

Copy link
Copy Markdown
Owner

I havent really been using Typescript lately- what is the best way to verify that the Types are correct? Say we get a PR that breaks a type- how do we run a test that picks that up?

@mikaelkaron

Copy link
Copy Markdown
Contributor Author

I've completed a first round of types generated from JSDoc now and it would be awesome if someone can help me review that the types I've documented/generated are correct. Generated types are not as good as manually created types, for instance:

  • Generics are not that easy to get right
  • Not able to generate interface - it's always a type
  • Parameter documentation is not extracted to the generated type
  • You are supposed to be able to generate types to a specific types folder and even a separate index.d.ts but I have not been able to do that yet.

It's possible that's due to me not understanding how to do that - if someone knows how to address the above please go for it ;)

I havent really been using Typescript lately- what is the best way to verify that the Types are correct? Say we get a PR that breaks a type- how do we run a test that picks that up?

I think the best we can do is to add tsd tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants