typescript - 带有打字稿的winston自定义传输
问题描述
我很难尝试使用打字稿编译winstom 自定义记录器。
我将此 js代码作为起点,并考虑到来自 github 的评论:
import * as Transport from 'winston-transport'
//
// Inherit from `winston-transport` so you can take advantage
// of the base functionality and `.exceptions.handle()`.
//
module.exports = class YourCustomTransport extends Transport {
constructor(opts) {
super(opts);
//
// Consume any custom options here. e.g.:
// - Connection information for databases
// - Authentication information for APIs (e.g. loggly, papertrail,
// logentries, etc.).
//
}
log(info, callback) {
setImmediate(() => {
this.emit('logged', info);
});
// Perform the writing to the remote service
callback();
}
};
但我得到了错误:
Type 'typeof TransportStream' is not a constructor function type.ts(2507)
我尝试了几种替代方法,但总是被打字稿编译器阻止。
解决方案
当我将您的导入语句替换为
import Transport = require('winston-transport');
那么tsc没有任何抱怨。这类似于内置文件传输导入winston-transport 的方式。
推荐阅读
- java - Selenium Java - 如何使用 @ 符号警报登录
- angular - 在 Angular Firestore 中获取 documentid
- c# - Unity中如何给相机的边缘碰撞
- list - apache freemarker - 将列表呈现为表格
- highcharts - Highmaps:如何更改州名
- r - 在数据框中的 2 个变量上使用的 tapply 会给出错误消息
- python - 将 Python 列表中的值输出到 csv
- mongodb - 在磁盘故障的情况下MongoDB可以故障转移吗
- python - 如何使用字符串作为变量?
- flutter - Flutter SingleChildScrollView 允许子溢出