我正在尝试安装模块log4ts,该模块的Layouts和Appender有一些可选的类型定义。这些实现不包含在主log4ts.d.ts定义文件中。但是,它们是单独包含的,例如here is the ConsoleAppender definition。我的问题是,如何安装这些额外的定义文件?
这是我试图做的事情:
npm install log4ts --save
typings install npm:log4ts/build/log4ts.d.ts --save --global
这允许我导入此主要定义中的类型:
// Works!
import { Logger, LoggerConfig } from "log4ts";
现在尝试安装其他类型定义:
typings install npm:log4ts/build/appenders/ConsoleAppender.d.ts --save
尝试导入:
import { ConsoleAppender } from "log4ts";
import { ConsoleAppender } from "log4ts/ConsoleAppender";
这两个都给出了错误消息:"模块log4ts没有导出的成员' ConsoleAppender'"
在上述安装命令之后,我的typings.json
如下所示:
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160602141332",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"log4ts": "npm:log4ts/build/log4ts.d.ts",
"node": "registry:dt/node#6.0.0+20160720070758",
"selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654",
"source-map": "registry:dt/source-map#0.0.0+20160317120654",
"uglify-js": "registry:dt/uglify-js#2.6.1+20160316155526",
"webpack": "registry:dt/webpack#1.12.9+20160724112410"
},
"dependencies": {
"log4ts": "npm:log4ts/build/appenders/ConsoleAppender.d.ts"
}
}
答案 0 :(得分:1)
根据log4ts/ConsoleAppender.d.ts
,您有默认导出
export default class ConsoleAppender extends BaseAppender implements IAppender {
append(entry: LogEntry): void;
clear(): void;
}
因此,为了使代码正常工作,您只需要导入默认导出。
import ConsoleAppender from "log4ts/ConsoleAppender"; // Without the { }
答案 1 :(得分:0)
您是否尝试过使用--global参数进行安装?