TypeScript类型定义文件的格式是否正确?

时间:2016-03-27 06:40:44

标签: javascript node.js typescript

我最近一直在学习TypeScript,并且对如何将节点模块导入TypeScript项目感到困惑。我发现文档在这些问题上有点弱,但也许这只是我。

特别是,我遇到了mathjs库的DefinitelyTyped类型定义问题。无论我使用三次斜杠引用还是将mathjs.d.ts添加到tsconfig.json,发出的js似乎都不包含此特定模块的require语句。我找到了一个似乎对我有用的解决方案,但我想知道我是否遗漏了一些东西。原始和我对输入定义文件的更改在这里。这个问题只是定义文件与最新的TypeScript过时了吗?

来自存储库的

.d.ts

declare var math: mathjs.IMathJsStatic;

declare namespace mathjs {

    type MathArray = number[]|number[][];
    type MathType = number|BigNumber|Fraction|Complex|Unit|MathArray|Matrix;
    type MathExpression = string|string[]|MathArray|Matrix;

    export interface IMathJsStatic {

        <Bunch of Definitions>
    }
}

我的更改

 declare var math: mathjs_namespace.IMathJsStatic;

    declare namespace mathjs_namespace {

        type MathArray = number[]|number[][];
        type MathType = number|BigNumber|Fraction|Complex|Unit|MathArray|Matrix;
        type MathExpression = string|string[]|MathArray|Matrix;

        export interface IMathJsStatic {

            <Bunch of Definitions>
        }
    }

declare module "mathjs" {
    export = math;
}

0 个答案:

没有答案
相关问题