Implement .d.ts generator #46
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
We need a facility that will take a (fully merged) TypeDispatcher
dispatchand write out a high-fidelity TypeScript .d.ts file for thisdispatchobject, with all of its associated types and its operations, with an overload for each showing "all" of the types it can be called with and the resulting return type in each case. I put "all" in quotes because currentlymath.addcan addnumberandComplex<number>andComplex<Complex<number>>andComplex<Complex<Complex<number>>>(octonions!) and so on ad infinitum. I am not certain that TypeScript can express all that in a finite way. Maybe it can, but it's also not critical as I doubt anyone will fault us if the typing doesn't have typings for Complex four deep (or even three deep...). So as a first past, I think we can just pick a max instantiation depth and generate typings up to that depth.Note that this facility as envisioned would not correctly type
Maybe there are tricks for that, I don't think so, but at least as initially envisioned one would have to make a module "mymath", merge all the stuff you want into the TypeDispatcher exported from mymath, run as a build step the .d.ts generator on the resulting dispatcher and install that as the mymath.d.ts, and then you could import from mymath with TypeScript then knowing you can call
mymath.foo(true, false). Hopefully that's good enough for now.Feat: .d.ts generatorto Implement .d.ts generatorI think for a first version we should start "simple", ensuring we have a basic implementation, at least as good as the current manually created index.d.ts of mathjs. From there we can see how far we can go and improve it further in smaller steps.