josdejong / josdejong/mathjs

Insufficient typing for `add`, `subtract`, `dotMultiply` etc

Open
#2,349 0 comments 3 reactions 0 assignees View on GitHub
help wanted typescript
Dominant language
JavaScript
Stars
15.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

The functions
* [`add`](https://github.com/josdejong/mathjs/blob/develop/types/index.d.ts#L770)
* [`subtract`](https://github.com/josdejong/mathjs/blob/develop/types/index.d.ts#L1119)
* [`dotDivide`, `dotMultiply`, `dotPow` etc.](https://github.com/josdejong/mathjs/blob/develop/types/index.d.ts#L837)

lack sufficiently fine-grained type definitions. In particular, this produces an error:
```typescript
math.add([1, 2], [3, 4])[0];
// Element implicitly has an 'any' type because expression
// of type '0' can't be used to index type 'MathType'.
// Property '0' does not exist on type 'MathType'
```
while it should be clear that the result is a one-dimensional array.

Adding some overloads would make the TypeScript experience with Mathjs much smoother.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.