josdejong/mathjs

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

Ouverte

#2 324 ouverte le 21 sept. 2021

 (1 commentaire) (1 réaction) (0 personne assignée)JavaScript (1 314 forks)batch import
bughelp wantedtypescript

Métriques du dépôt

Stars
 (15 065 étoiles)
Métriques de merge PR
 (Métriques PR en attente)

Description

I'm customizing mathjs extending its types and methods. In JS I can register a type :

  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:

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!([ ... ]);

Guide contributeur