【问题标题】:DefinitelyTyped log4javascript missing module declaration绝对类型的 log4javascript 缺少模块声明
【发布时间】:2016-12-14 08:16:30
【问题描述】:

我很难在我的项目中使用以下类型文件:

https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/log4javascript

显然,该文件缺少模块声明,当我将以下语句放入我的 typescript 文件时,导致 typescript 抱怨找不到模块“log4javascript”:

import * as log4javascript from 'log4javascript';

当我手动编辑通过运行命令安装的 index.d.ts 文件时

typings install dt~log4javascript --global --save

我添加了这个模块声明:

declare module "log4javascript" { import test = log4javascript; export = test; }

在文件末尾,编译器不再抱怨,我的代码甚至可以在不使用import * 语句的情况下工作。

那么我应该如何使用类型文件,以便我可以将 log4javascript 与 typescript 一起使用?

更新

我已经设法通过创建一个custom.d.ts 文件来解决这个问题,该文件声明 log4javascript 模块以及生成的类型的根 index.d.ts 并在我的 main.ts 文件中添加了一个 ///<reference path="..." /> 语句,供 requirejs 使用.
我仍然觉得这不是正确的做法,但目前可行。

【问题讨论】:

    标签: typescript definitelytyped log4javascript


    【解决方案1】:

    我设法通过创建一个custom.d.ts 文件来解决这个问题,该文件声明 log4javascript 模块以及生成的类型的根 index.d.ts,并在我的 main.ts 文件中添加了一个 ///<reference path="..." /> 语句,供 requirejs 使用. 我仍然不觉得这是正确的做法,但它现在有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-20
      • 2019-03-21
      • 2017-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-02
      相关资源
      最近更新 更多