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;
To declare a global variable in TypeScript, create a . d. ts file and use declare global{} to extend the global object with typings for the necessary properties or methods.
declare global is used inside a file that has import or export to declare things in the global scope. This is necessary in files that contain import or export since such files are considered modules, and anything declared in a module is in the module scope.
To import a class from another file in TypeScript: Export the class from file A , e.g. export class Employee {} . Import the class in file B as import { Employee } from './another-file' . Use the class in file B .
With TypeScript 3.8, you can import a type using the import statement, or using import type .
npm install --save-dev @types/bluebird-global
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With