【问题标题】:Error with typescript nodejs when using new keyword in a pc and not using new in another在 PC 中使用 new 关键字而不在另一个中使用 new 时 typescript nodejs 出错
【发布时间】:2019-03-28 03:20:00
【问题描述】:

我正在使用带有 typescript 的 Firebase 函数,并且我正在尝试使用这一行来实例化谷歌云存储:

const gCS = gcs({ keyFilename: 'service-account.json' })

gcs 是import * as gcs from '@google-cloud/storage'。它对我来说很好,但是我的同事在尝试部署时遇到了这个错误:

错误 TS2348:“typeof Storage”类型的值不可调用。你是否 是指包含“新”吗?

如果他将上面的行改为:

const gCS = new gcs({ keyFilename: 'service-account.json' })

错误对他来说消失了,但是我是那个有错误的人:

错误 TS2350:只能使用 'new' 调用 void 函数 关键字。

如果我们有同一个项目,我们需要使用不同的代码怎么办?

【问题讨论】:

  • 你检查过你们两个库的版本相同吗?
  • 另外,请确保您的 @types npm 包为 @google-cloud/storage 在你们两个之间同步

标签: javascript node.js typescript firebase google-cloud-functions


【解决方案1】:

检查你们俩的@type 定义,也许有人忘记保存@types,并检查依赖版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-28
    • 2016-10-12
    • 2011-05-24
    • 2012-08-12
    • 1970-01-01
    • 2013-01-27
    • 1970-01-01
    相关资源
    最近更新 更多