Bunyan Logger 打字稿配置 Errror named logger cannot be named

Bunyan Logger typescript configuration Errror named logger cannot be named

我正在尝试为 NodeJS 项目配置我的 Bunyan 记录器。此配置工作正常,直到我开始将我的项目转换为 Typescript。

这是在文件 MyLogger.ts:

中配置我的记录器的配置函数
import { createWriteStream } from 'fs'
import { stdSerializers, createLogger } from 'bunyan'
const pkg = require('../../package.json')

export default function (logLevel: string = 'debug', logFolder: string) {
  const logOptions = {
    serializers: stdSerializers,
    name: `${pkg.name}-${pkg.version}`,
    streams: [
      { level: 'error', stream: process.stderr },
      { level: logLevel, stream: process.stdout }
    ]
  }

  if (logFolder) {
    logOptions.streams.push(
      { level: logLevel, stream: createWriteStream(`${logFolder}/${pkg.name}.log`) })
  }

  const logger = createLogger ({
    name: logOptions.name,
    streams: logOptions.streams
  })

  return logger
}

现在编译打字稿时,出现以下错误:

lib/config/MyLogger.ts(5,1): error TS4058: Return type of exported function has or is using name 'Logger' from external module "project-folder/node_modules/@types/bunyan/index" but cannot be named.

我使用的节点版本:6.9.2 班扬版本:1.8.5 @types/bunyan": "0.0.35

任何有助于理解错误或如何解决这个问题的帮助..都会很棒。 谢谢

基于此处的打字稿问题:TS4023

我通过添加一个导入得到了编译 运行:

import * as Logger from '@types/bunyan'

然后将 return 类型添加到我导出的函数中作为 Logger