Repository: TypeScript
Issue: Lib dependencies are transitive
Labels: Suggestion,In Discussion

<!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨

Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common "Bugs" That Aren't Bugs section!

Please help us by doing the following steps before logging an issue:
  * Search: https://github.com/Microsoft/TypeScript/search?type=Issues
  * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ

Please fill in the *entire* template below.
-->

<!--
Please try to reproduce the issue with the latest published version. It may have already been fixed.
For npm: `typescript@next`
This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly
-->
**TypeScript Version:**  3.8.3

<!-- Search terms you tried before logging this (so others can find this issue more easily) -->
**Search Terms:** lib target dependencies triple-slash

**Code**

I have a reproduction repository at https://github.com/astorije/repro-tsc-lib-issue.
Essentially, consider the following code:

```ts
console.log(Object.values({ foo: BigInt(42) }));
```

`Object.values` is a ES2017 feature, and `BigInt` is a ES2020.
Also consider the `target` is `tsconfig.json` is `es2015`, and `lib` is either not specified or simply contains `es2015` and `dom`.

**Expected behavior:**

Given the code and the TS configuration above, the type checker should _always_ fails with:

```ts
index.ts:2:20 - error TS2339: Property 'values' does not exist on type 'ObjectConstructor'.

2 console.log(Object.values({ foo: BigInt(42) }));
                     ~~~~~~

index.ts:2:34 - error TS2304: Cannot find name 'BigInt'.

2 console.log(Object.values({ foo: BigInt(42) }));
                                   ~~~~~~
```

And if you only have `typescript` as a dependency in `package.json`, that is indeed what you'll get. So far, so good. **See the `expected` folder of my repro repo.**

**Actual behavior:**

If you have a (direct or indirect) dependency to `@types/node`, or if _any_ dependency contains a declaration file that has `/// <reference lib="es2018" />`, `/// <reference lib="es2020.bigint" />`, etc., the type checker will now stop reporting these errors. **See the `actual` folder of my repro repo.**

This seems significant to me because it means that dependencies can silence potential browser incompatibilities. If I specified a `target` of `es2015`, with no extra `lib`, Babel transpiling, or polyfills, I should not be able to compile the code above.

Is there something obvious I'm missing? I realize it's the very design of `lib`but as explained in #15732, that assumes the project uses polyfills, which is not something that can be enforced/checked by a third-party library at compile time.

**Related Issues:** <!-- Did you find other bugs that looked similar? -->

Apologies for the vagueness of the search terms. It's significant enough that it must already exist in an issue or a StackOverflow question, but after spending some time looking, I did not find anything similar.

The only issues that seem somewhat related, but different:
- https://github.com/microsoft/TypeScript/issues/33111
- https://github.com/microsoft/TypeScript/issues/35656
- https://github.com/microsoft/TypeScript/issues/15732