1

From this question and this code, it's clear that using lib in the tsconfig will not polyfill any functionality you're using that isn't supported in your target environment.

If that's true, however, what is the use case supposed to be? If I had a polyfill that I'd pulled in, like bluebird, I would be using the DefinitelyTyped definition files. Is there a combination of target and lib that is intended to fix a common pattern in TS?

ABMagil
  • 4,579
  • 4
  • 21
  • 35
  • If you're targeting browsers that have a native Promise, you can use `lib` to provide the definitions without using a polyfill. – Heretic Monkey Jun 11 '18 at 17:13
  • but if that's my runtime, I'm targeting `es6` not `es5`, and TS will automatically know `Promise` is a thing – ABMagil Jun 11 '18 at 17:14
  • Yeah, that was just an example... it's used for JavaScript engine/runtime features that don't necessarily have a pre-made definition file. And for things which one runtime might provide, but another doesn't. For example, there may be a browser that needs `es5` for some things, like not supporting arrow functions, but does include, say, generators. You could use a combination of `lib` entries to suit the needs of that runtime. – Heretic Monkey Jun 11 '18 at 17:19

1 Answers1

2

The default lib includes the DOM, but you might be running in a non-browser environment like node, so getting rid of that is useful.

You also might be running in a webworker context, which has a separate lib setting.

You also might be using a comprehensive polyfill library that you don't need specific types for.

It's also possible your host e.g. supports some ES6 APIs but don't support a certain ES6 syntax, so you can "mix and match" to target environment that don't support 100% of any particular spec level.

Ryan Cavanaugh
  • 209,514
  • 56
  • 272
  • 235