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

Generate typescript definitions from JSDoc #110

Open
dchiquito opened this issue May 26, 2022 · 0 comments
Open

Generate typescript definitions from JSDoc #110

dchiquito opened this issue May 26, 2022 · 0 comments

Comments

@dchiquito
Copy link
Contributor

It would be nice if cabal-core exposed some Typescript definition files (*.d.ts) that define the shape of the API. These types make cabal-core usable in other Typescript projects, and provide useful autocomplete information for IDEs like VSCode.

Typescript can generate these files automatically using a combination of type inference and JSDoc. I have a branch that fixes most of the typing errors and includes some some .d.ts files generated by running tsc. Ideally, we would have a simple script npm run generate-types or something that would regenerate the definition files ( inform the user of any type errors, another bonus!) and we would just run that script before releasing to keep the types up to date.

Sadly, the Cabal class is defined as a function which recognizes when it is being called as a function instead of a constructor and corrects that. However, this is too clever for Typescript to automatically recognize while also recognizing that Cabal extends EventEmitter.

One solution is to declare Cabal as a normal ES6 class instead of a constructor: class Cabal extends EventEmitter {...}. However, since the canonical way to instantiate a new Cabal is therefore Cabal(...) instead of new Cabal(...), this would be a breaking API change, which is a lot to ask just to add some typing support.

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

No branches or pull requests

1 participant