josdejong / mathjs

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

Easier types when working with "create" #2322

Open PaulRBerg opened 3 years ago

PaulRBerg commented 3 years ago

I followed the custom bundling docs and created my own instance of math.js, like this:

const math = create({ addDependencies, bignumberDependencies, divideDependencies, meanDependencies }, config);
const mbn = this.math.bignumber!;

What I don't like is that I have to use the ! non-null assertion operator, even if it is clear that the bignumber property should be non-null (as per the bignumberDependencies object passed to create).

I further had to disable the @typescript-eslint/no-non-null-assertion ESLint rule, because the lint task was failing.

My feature request: let the compiler know that the objects returned by create are non-null, based on the inputs provided.

josdejong commented 3 years ago

Thanks for reporting Paul. It would be nice if it's possible to improve the type definitions. Anyone able to look into this? Help would be very welcome.