josdejong / josdejong/mathjs

TypeScript: inconsistent factory signature (unable to declare custom dependencies)

Open
#2,324 1 comment 1 reaction 0 assignees View on GitHub
bug help wanted typescript
Dominant language
JavaScript
Stars
15.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

I'm customizing mathjs extending its types and methods.
In JS I can register a type :
```js
factory('DateTime', ['typed'], function createDateTime({ typed }: { typed?: any }) {
typed.addType({
name: 'DateTime',
test: (x: any) => x && x.constructor.name === 'DateTime'
})
return DateTime
}),
```
and then use it as a dependency:
```js
factory('datetime', ['typed', 'DateTime'], function createDateTime({ typed, DateTime }) {}
```
but in TypeScript it's not possible - I'm getting:
Type '"DateTime"' is not assignable to type 'keyof MathJsStatic'.

PS> And BTW creating math object is also quite confusing in TypeScript:
```
import { create, all, factory } from 'mathjs';
const mathjs = create(all);
mathjs!.import!([ ... ]);
```

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.