Skip to content

Intersection of features in modular lib files #11093

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

Closed
T-Hugs opened this issue Sep 23, 2016 · 8 comments
Closed

Intersection of features in modular lib files #11093

T-Hugs opened this issue Sep 23, 2016 · 8 comments
Labels
Docs The issue relates to how you learn TypeScript

Comments

@T-Hugs
Copy link

T-Hugs commented Sep 23, 2016

TypeScript Version: 2.0.3

It is very unclear how to effectively use the --lib compiler option. It appears there is a default set of libs that are included (i.e. when no --lib is specified). If any libs are specified with --lib, then it seems this default set gets replaced with the set you provide. I haven't been able to find any documentation on exactly what is in the default set.

Here's the issue I'm running into. I want to use the [default set] + es2015.collection. I've tried a number of things.

  • --lib es2015.collection OR --lib es6 - Lots of errors because DOM isn't declared
  • --lib es6,dom,scripthost,webworker - Several errors about duplicate signatures and declarations, e.g.
    lib.dom.d.ts(2145,5): error TS2375: Build: Duplicate number index signature.
    lib.dom.d.ts(3772,14): error TS2403: Build: Subsequent variable declarations must have the same type. Variable 'srcElement' must be of type 'any', but here has type 'Element'.
  • [no --lib option] - Can't use ES6 sets/maps.

Expected behavior:
Either the set of libs you can import needs to be disjoint, or the compiler should be able to handle duplicate declarations in these files.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 23, 2016

The defaults are:

  • if --target ES5 => dom,es5,scripthost
  • if --target ES6 => dom,es6,dom.iterable,scripthost

Some notes,

  • webworker is for WebWorker environments, these do not have DOM. so mixing dom and webworker do not make much sense.
  • scripthost is for windows scripting host libraries. if you are not writing a windows script or a website that uses ActiveXObject, then no need for this.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 23, 2016

@mhegazy mhegazy added the Docs The issue relates to how you learn TypeScript label Sep 23, 2016
@T-Hugs
Copy link
Author

T-Hugs commented Sep 23, 2016

Thanks @mhegazy. There's one instance in our source where importScripts is used. When I don't specify --lib, it compiles fine. When I add --lib dom,es5,scripthost I get this error:
DiscussionRenderer.ts(130,33): error TS2304: Build: Cannot find name 'importScripts'.

Also, just a nit, the default values you added should go in the Default column on the markdown page :)

@T-Hugs
Copy link
Author

T-Hugs commented Sep 23, 2016

Also, you said for es6 targets, dom.iterable is one of the default libs. Did you mean es2015.iterable?

@kitsonk
Copy link
Contributor

kitsonk commented Sep 23, 2016

Also, you said for es6 targets, dom.iterable is one of the default libs. Did you mean es2015.iterable?

It isn't a mistake. lib=es6 includes the es2015.iterable, but there are some DOM interfaces that are exposed as iterables in a ES6 compliant host, therefore dom.iterable.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 23, 2016

here's one instance in our source where importScripts is used.

yes. the import script is more of an anomaly. it should not have been ever added to the library. but it is kept there for back compat purposes. so it was intentionally omitted.

@bborowin
Copy link

bborowin commented Mar 3, 2017

importScripts is a part of web worker functionality -- how else is it possible to include scripts (eg, lodash)??

@mhegazy
Copy link
Contributor

mhegazy commented Mar 4, 2017

if you are using web workers use --lib webworkers

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Docs The issue relates to how you learn TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants