【问题标题】:Global import in Typescript?Typescript 中的全局导入?
【发布时间】:2017-04-01 20:31:35
【问题描述】:

我基本上想用 Bluebird 替换 Typescript (v2.0.10) 中的 Promise 定义。我读了很多关于此的内容,但结果很困惑——这可能吗?

我真的不想在每个 TS 文件的顶部都这样做:

import * as Promise from "bluebird";

我尝试在我的_stubs.d.ts 中这样做,但无济于事:

import * as Bluebird from "bluebird";
declare var Promise: typeof Bluebird;

【问题讨论】:

标签: typescript promise bluebird


【解决方案1】:
  1. npm install --save-dev @types/bluebird-global
  2. 编辑您的tsconfig.json 以在types 数组中列出bluebird-global

    {
      "compilerOptions": {
        "types": [
          "bluebird-global"
        ],
        // the rest of the options
      }
    }
    

编辑:

如果您不在tsconfig.json 中使用compilerOptions.types,则不需要第2 步。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-20
    • 1970-01-01
    • 1970-01-01
    • 2012-07-02
    • 1970-01-01
    • 2017-04-30
    • 2020-01-23
    相关资源
    最近更新 更多