Skip to content

Provide a way to load Bluebird globally in es6 compilation target. #12382

Closed
@d-ph

Description

@d-ph

TypeScript Version: 2.1.1

Code

  1. Either git clone -b e5-and-core-js-case https://github.com/d-ph/typescript-bluebird-as-global-promise.git or git clone -b vanilla-es6-case https://github.com/d-ph/typescript-bluebird-as-global-promise.git
  2. cd typescript-bluebird-as-global-promise
  3. npm install
  4. Edit node_modules/@types/bluebird/index.d.ts by adding export as namespace Promise; above the export = Bluebird; line. (please ignore the fact that you're hacking 3rd code for a second)
  5. npm run tsc

Expected behavior:
Compilation succeeds. Promise is detected to be declared by bluebird.d.ts.

Actual behavior:
Tsc says, that lastly, delay and finally don't exist on type Promise.

More info:
Bluebird polyfills the global Promise, but Typescript ignores that (i.e. ignores the export as namespace Promise; line) when Promise is already defined by either the lib.es2015.promise.d.ts es6 declaration file or the core-js declaration file.

I think the problem doesn't lie in Typescript's ignoring the Bluebird's export as namespace Promise;, but in some sort of precedence order, when global symbols are being declared by .d.ts files. What I'd like to be able to do is to somehow tell Typescript, that Bluebird is my effective Promise provider. Maybe this could be achieved by making Typescript respect the order of @types listed in tsconfig.json's compilerOptions.types array? I.e. the last item in that array wins any global namespace conflict?

This problem most likely affects any polyfilling library in the wild, where the polyfill is.. more convenient to use than the standard solution, so devs decide to use it even after starting using newer js standard.

Btw. this ticket is sort of blocked by #10178 at the moment.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions