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

Automatically generate type definitions #1779

Open
m93a opened this issue Mar 17, 2020 · 1 comment
Open

Automatically generate type definitions #1779

m93a opened this issue Mar 17, 2020 · 1 comment

Comments

@m93a
Copy link
Collaborator

m93a commented Mar 17, 2020

I know that this repository is JavaScript by choice and I'm definitely not proposing to rewrite it in TypeScript. However, most modern IDEs leverage type definitions to show tooltips and hints even for developers using pure JavaScript. In the ideal case scenario, one doesn't even have to open the documentation, because they see everything in their editor:

image

The mathjs source code contains all the important information: the methods are strongly typed thanks to typed-function, every method has a jsDoc comment with complete specification attached to it. But currently, none of this information is exported as type definitions. For types we're dependent on DefinitelyTyped which has to be manually fixed every time a new version comes out, and is prone to misunderstanding and mistakes in transcribtion.

This code duplication is unfortunate and could be avoided. TypeScript supports generating type definitions from js files. If mathjs were just a traditional ES6 module, setting up type generation would be trivial. But since there appears to be some complicated interdependency between the files, it might be a bit trickier.

EDIT: I'm attaching a link to a string matching trick for TypeScript, so that I can find it here if I need it.


@josdejong I'm willing to invest some of my time to investigate this issue further, but I don't want to waste my time, so please let me know if you'd be interested in this.

Also, I'd like to ask, why does mathjs have a custom dependency loader (utils/factory.js). Aren't the already existing mechanisms of ES6 modules enough?

@josdejong
Copy link
Owner

So far we've chosen not to integrate TS type definitions inside the library itself, see #244. My main concern was having to maintain all these type definitions inside the library instead of keeping it just plain JS.

I do like your idea of automatically generating TypeScript definitions, if that is possible I think it's worth bundling the generated definitions in the library itself. It would be great if you could explore the possibilities Michal!

Also, I'd like to ask, why does mathjs have a custom dependency loader (utils/factory.js). Aren't the already existing mechanisms of ES6 modules enough?

The factory.js file is a mechanism for dependency injection, it is not about import/export.

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

No branches or pull requests

2 participants