josdejong/mathjs

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

開放

#2,324 建立於 2021年9月21日

 (1 則留言) (1 個反應) (0 位負責人)JavaScript (1,314 個分叉)batch import
bughelp wantedtypescript

倉庫指標

星標
 (15,065 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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

貢獻者指南