Repository navigation
Promise.all returns all values with type of the most common interface. #16017
Description
Activity
Looks like the issue here is we have two definitions for
Promise.all, one inlib.es2015.promise.d.tsand one inlib.es2015.iterable.d.ts, the earlier defines a set of overloads with a tuple types and thus get type of[dataA, dataB]correctly, the other has an array overload, that takes a list and returns a list, and thus gets the type as the best common type betweenAandB.The fix seems to reorder these overloads somehow to make sure the overloads from
lib.es2015.promise.d.tscome afterlib.es2015.iterable.d.ts,; or thatlib.es2015.iterable.d.ts, redefines the same overloads.As a workaround, list the
--libexplicitly with this order:--lib es5,es2015.promise,es2015.iterableThanks Mohamed Hegazy (@mhegazy)!
I have applied your workaround and may confirm it works.
I modified my tsconfig.json to include this:"lib": [ "dom", "es5", "es2015.promise", "es2015.iterable", "es2017" ],Still I find this
--liboption a bit confusing, I have read specifications here:
https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#including-built-in-type-declarations-with---libBut it is still not very clear what to specify there if I target the browser and want to have available all features polifilled by
core.jsfor instance. Should I specifyes2015 or es2016 or es2016.array.includeif I have already specifiedes2017?Is there somewhere better documentation about all of this?
--targetis what version of ECMAScript is your target engine supporting. for instance--target ES5would be safe if you are using IE11.--target ES2017is safe if you are using node@7.0.By default a matching version of the library is added to your compilation based on your target, so
--target ES6gets you the equivalentlib.es6.d.ts, and--target ES2017gets youlib.es2017.d.ts. By default you also get things likeDOMAPIs.Sometimes you want to add definitions that are not part of the standard, for instance ones you have polyfiled, e.g.
Promise. for these we recommend explicitly adding the library portion that you need, e.g.--target es5 --lib es5,es2015.promise.Library versions are cumulative, so if you set
--lib es2017this includes definitions ines2017,es2016andes5.hope that helps.
Andy (Andrewkraft) (@Andy-MS) it is because we pick up overload
all<TAll>(values: Iterable<TAll | PromiseLike<TAll>>): Promise<TAll[]>;fromlib.es2015.iterable.d.tsdue to how it is order.I think the fix here is to remove Promise constructor definition from
lib.es2015.iterable.d.tsand just reference ``lib.es2015.promise.d.ts`- addedFixedA PR has been merged for this issueA PR has been merged for this issue
on Jun 15, 2017 - locked and limited conversation to collaborators
on Jun 14, 2018
TypeScript Version: 2.3.3 / nightly (2.4.0-dev.20170523)
The problem can be reproduced with this code:
Expected behavior:
Compiles without errors
Actual behavior:
Compilation error:
I see that interface
Bis compatible with interfaceA, but I don't think thatPromise.allshould return all values asA[].When you change interface
Afor example adding a fieldfieldA, then interfaceBis not compatible anymore and the code compiles without errors.I have created very small repository which reproduces this issue.
https://github.com/megaboich/ts-promise-all-issue