打字稿中的全局导入?

Jos*_* M. 8 promise typescript bluebird

我基本上想用PromiseTypesbird 替换Typescript(v2.0.10)中的定义.我读了很多关于这个但是出来很困惑 - 是否有可能?

我真的不想在每个TS文件的顶部执行此操作:

import * as Promise from "bluebird";
Run Code Online (Sandbox Code Playgroud)

我试图在我这样做_stubs.d.ts无济于事:

import * as Bluebird from "bluebird";
declare var Promise: typeof Bluebird;
Run Code Online (Sandbox Code Playgroud)

d-p*_*-ph 5

  1. npm install --save-dev @types/bluebird-global
  2. 编辑您tsconfig.jsonbluebird-globaltypes数组中列出:

    {
      "compilerOptions": {
        "types": [
          "bluebird-global"
        ],
        // the rest of the options
      }
    }
    
    Run Code Online (Sandbox Code Playgroud)

编辑:

如果你不使用第2步是没有必要compilerOptions.types在你的tsconfig.json