Mathjs: @types/mathjs out of date

Created on 9 Jun 2019  路  24Comments  路  Source: josdejong/mathjs

To use import syntax for the variance function, it requires a commented @ts-ignore directive to force the TypeScript compiler to pass. I don't mind submitting a pull request, I just need to know which repo I need to fork to fix this.

// @ts-ignore: the variance function exists, and is being deprecated in the `var` form
import { mean, median, variance, round } from "mathjs";

I happen to be using this library in my as-pect cli testing suite and have had great success in getting my Web Assembly modules tested with performance metrics measurements using the mathjs functions.

Please advise.

Most helpful comment

I'll try to inspect the source code too. If you don't mind, it might be a day or two.

All 24 comments

There is a TypeScript in definition for mathjs in https://github.com/DefinitelyTyped/DefinitelyTyped. Mathjs itself is plain JavaScript. I think it can use some updates, since yesterday we released v6.0.0 with some breaking changes in the API.

Ah okay. So I would have to fork the definitely typed repo.

Is there an easy way of getting the list of changes to submit a pull request?

Thanks for picking this up!

The changes are described in the HISTORY.md:

https://github.com/josdejong/mathjs/blob/develop/HISTORY.md#2019-06-08-version-600

does that help?

I'll try to inspect the source code too. If you don't mind, it might be a day or two.

As talked with @jtenner in https://github.com/DefinitelyTyped/DefinitelyTyped/issues/36381#issuecomment-507364488, I would like to take a look at @types/mathjs package. Could @josdejong assign this issue to me?

:+1: thanks

@josdejong A quick question about function create(factories, options). Is the factories parameter supposed to be extensible by users? Or it is pure internal?

Since I didn't see any documents regarding to using custom factories, I wonder if it is necessary to add types to factories parameter or simply leave it as any.

Please advise. Thank you!

The factories parameter in create(factories [, options]) is an object containing factory functions and/or nested objects with factory functions, something like:

const factories = {
  myFunctionDependencies: {
    functionADependencies: {
      ...
    },
    createFunctionA: function (...) { ... },
    createFunctionB: function (...) { ... },
    ...
  },
  createMyFunction: function (...) { ... }
}

A factory function is simply a function with a specific signature, from the docs:

A syntax of factory function is:
factory(name: string, dependencies: string[], create: function, meta?: Object): function

Here some related docs that may help:

https://mathjs.org/docs/core/extension.html#factory-functions
https://mathjs.org/docs/custom_bundling.html

Thanks @josdejong , I'll put this into typing.

@josdejong the PR has been merged and this issue can be closed soon.

@jtenner @josdejong The PR has been merged and package was uploaded to npm; can we have this issue closed?

I suppose! Thanks for the fix.

I'm curious as to whether any of you guys got the example from the docs (Using just a few functions) working with typescript:

import {
  create,
  fractionDependencies,
  addDependencies,
  divideDependencies,
  formatDependencies
} from 'mathjs'
// ...

obviously fails as the typings don't contain e.g. fractionDependencies as export.

Worked for the little bits that I used. I hardly use it though. I moved away from using mathjs as a dependency in my biggest project so I haven't been able to check it well enough.

Thanks @charlee .

The exported fractionDependencies, addDependencies, etc are quite essential in order to use tree-shaking. It should be quite easy to create the list with all exported *Dependencies, and simply define them as an Object already helps a lot (without specifying the exact properties that it contains, these details are not needed for normal use)

Anyone interested in adding these to the TypeScript definitions?

@josdejong I would be happy to fix this but may not be available in the following couple of days. Will try to do it by end of week.,

Thanks a lot @charlee for picking this up :+1:

@josdejong I just realized there's another import mathjs/number which involves different typings. Looks like it is new in mathjs 6 and I can't use previous v5 typings directly, so I need some more time to go over all the math functions to create the typings.

Yes you're right @charlee . These are the two entry points that there are for mathjs the mathjs/number import contains a subset of all functions of mathjs: these are number-only implementations of all relevant functions of mathjs (it misses functions that are for calculations with matrices for example).

There is no deadlines here, take your time, I'm glad you're willing to put effort into getting the TypeScript definitions up to date!

@josdejong I realized that it would be a huge effort to review all the functions and do necessary changes, so I decided to submit a PR for dependencies only and continue my work on a separated PR. This is a relative small PR and wonder if you have time to review it. Thanks!

Looks like your PR is merged already? :)

@josdejong Yes its merged and published as @types/mathjs-6.0.1. I will revise all the functions and create types for number in another PR.

:+1: thanks for all your work

@charlee did you manage to write type definitions for the number types? I see this issue is still open.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

balagge picture balagge  路  5Comments

zzzgit picture zzzgit  路  4Comments

Lakedaemon picture Lakedaemon  路  5Comments

skgadi picture skgadi  路  3Comments

kyoncy picture kyoncy  路  4Comments