Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib.es2015.iterable.d.ts exports the Promise interface #12868

Closed
LucasSloan opened this issue Dec 13, 2016 · 3 comments
Closed

lib.es2015.iterable.d.ts exports the Promise interface #12868

LucasSloan opened this issue Dec 13, 2016 · 3 comments

Comments

@LucasSloan
Copy link

TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)

lib.es2015.iterable.d.ts exports the Promise interface, which is only used in lib.es2015.iterable.d.ts to help define the PromiseConstructor interface which isn't further used in lib.es2015.iterable.d.ts. Since both Promise and PromiseConstructor are declared in lib.es2015.promise.d.ts and the declaration for Promise in lib.es2015.iterable.d.ts is empty and the declaration for PromiseConstructor is incomplete and not linked to Promise, it seems like both should be removed from the lib.es2015.iterable.d.ts file.

As a result, I got a the compliler error
error TS2339: Property 'then' does not exist on type 'Promise<any>'
when I referenced Promise while importing iterable, and not promise instead of the expected
error TS2304: Cannot find name 'Promise'

@mhegazy
Copy link
Contributor

mhegazy commented Dec 13, 2016

And you do not want to include lib.es2015.promise.d.ts?

@yortus
Copy link
Contributor

yortus commented Dec 13, 2016

@LucasSloan see #6974 and in particular this comment and @yuit 's reply right after.

There is feature crossover here between Promises and Iterables. Some runtimes support one or the other or both or neither. So the --lib option makes it possible to get more granular type checking for your particular target, thanks to declaration merging over multiple lib files.

For example you might be sure to have a Promise polyfill, but don't want to rely on the presence of iterables, so you could include promise.d.ts but not iterable.d.ts. Then you could use promises, but you'd get a compiler error for using Promise.all() with an iterable. Which is better than getting a runtime error.

If you want to use both promises and iterables, then you must include both in your --lib option (or just use es2015 which has both).

@LucasSloan
Copy link
Author

Got it. Thanks!

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants