Description
TypeScript Version: 2.1.1
Code
- Either
git clone -b e5-and-core-js-case https://github.com/d-ph/typescript-bluebird-as-global-promise.git
orgit clone -b vanilla-es6-case https://github.com/d-ph/typescript-bluebird-as-global-promise.git
cd typescript-bluebird-as-global-promise
npm install
- Edit
node_modules/@types/bluebird/index.d.ts
by addingexport as namespace Promise;
above theexport = Bluebird;
line. (please ignore the fact that you're hacking 3rd code for a second) 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.