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 or git 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 adding export as namespace Promise; above the export = 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.
TypeScript Version: 2.1.1
Code
git clone -b e5-and-core-js-case https://github.com/d-ph/typescript-bluebird-as-global-promise.gitorgit clone -b vanilla-es6-case https://github.com/d-ph/typescript-bluebird-as-global-promise.gitcd typescript-bluebird-as-global-promisenpm installnode_modules/@types/bluebird/index.d.tsby addingexport as namespace Promise;above theexport = Bluebird;line. (please ignore the fact that you're hacking 3rd code for a second)npm run tscExpected behavior:
Compilation succeeds.
Promiseis detected to be declared by bluebird.d.ts.Actual behavior:
Tsc says, that
lastly,delayandfinallydon't exist on typePromise.More info:
Bluebird polyfills the global
Promise, but Typescript ignores that (i.e. ignores theexport as namespace Promise;line) whenPromiseis already defined by either thelib.es2015.promise.d.tses6 declaration file or thecore-jsdeclaration 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 effectivePromiseprovider. Maybe this could be achieved by making Typescript respect the order of@typeslisted in tsconfig.json'scompilerOptions.typesarray? 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.