josdejong / mathjs

An extensive math library for JavaScript and Node.js
https://mathjs.org
Apache License 2.0
14.32k stars 1.24k forks source link

Improve type definitions for 'mathjs/number' #2284

Open A-a-l-l-e-e-x-x opened 3 years ago

A-a-l-l-e-e-x-x commented 3 years ago

Hi,

I tried following the directions of the webpage regarding custom bundling ( https://mathjs.org/docs/custom_bundling.html ), but it seems like there is an issue with using the sub-modules when in a TypeScript project.

The error I get when trying to import mathjs/number as described in the article is as follows: import { create, all } from "mathjs/number"; Cannot find module 'mathjs/number' or its corresponding type declarations.

In my package.json, I have version 9.4.3 of mathjs, and 9.4.2 of @types/mathjs. I checked the installed mathjs in my node_modules, and its package.json does indeed export './number', so I'm confused as to why it's not being picked up. Could it be that type definitions are not being imported along with it, therefore throwing an error?

Maybe adding something like "mathjs/number": ["./index.d.ts"] to paths of mathjs's package.json could help? (It doesn't, but maybe something similar does)

m93a commented 3 years ago

Hey Alex! I'm afraid the type definitions of math.js are quite lacking at this point. We are shipping our own type definitions, so importing @types/mathjs isn't needed, however we don't currently have types for mathjs/number. And since mathjs/number and mathjs have slightly different APIs, I would not recommend trying to use the mathjs types for mathjs/number.

That said, any PR that would add types for mathjs/number is welcome!

jazzloffredo commented 1 year ago

@m93a Hello! I would be interested in adding types for mathjs/number if this is still needed.

josdejong commented 1 year ago

Thanks Jazz, yes we need types for mathjs/number. Thanks for your offer to work on that!