Josh M.
Josh M.

Reputation: 27811

Global import in Typescript?

I basically want to replace the Promise definition in Typescript (v2.0.10) with Bluebird. I read a lot about this but came out confused -- is it possible or not?

I really don't want to have to do this at the top of every TS file:

import * as Promise from "bluebird";

I tried to do this in my _stubs.d.ts to no avail:

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

Upvotes: 10

Views: 7152

Answers (1)

d-ph
d-ph

Reputation: 666

  1. npm install --save-dev @types/bluebird-global
  2. Edit your tsconfig.json to list bluebird-global in the types array:

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

Edit:

Step 2 is not necessary if you don't use the compilerOptions.types in your tsconfig.json.

Upvotes: 5

Related Questions