Skip to content

es2020.d.ts is included for a project configured to only use lib:["es5"] #42827

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
greyepoxy opened this issue Feb 16, 2021 · 5 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@greyepoxy
Copy link

Bug Report

πŸ”Ž Search Terms

  • lib
  • es2020
  • esnext
  • reference

πŸ•— Version & Regression Information

This is the behavior in every version I tried, and I reviewed the FAQ for entries about compilerOptions "lib" and "types"

⏯ Playground Link

Couldn't figure out how to add dependencies in the playground so uploaded an example repository:
https://github.com/greyepoxy/typescript-over-lib-inclusion-issue

πŸ’» Code

In a project with the following tsconfig.json excerpt,

{
    "compilerOptions": {
        "lib": ["es5"],
        "types": [],
        "skipLibCheck": true
    }
}

And the following code,

import { shallow } from "enzyme";

const bigInt = BigInt(9007199254740991);

πŸ™ Actual behavior

Compile succeeds without issue

πŸ™‚ Expected behavior

For the compiler to throw an Error because BigInt should not be defined because it is in the es2020 lib which is not included in the compilerOptions

I have done some analysis on why this occurring, please see the root cause section in the example project readme.

Why this Matters

In the company I work for (Tableau), several hundreds of web developers have depended on the tsconfig lib as a tool to try and prevent using new JavaScript features that are not present in IE11 (and other slower to update browsers). With the recent change to @types/node to always include the es2018 and parts of the es2020 lib, there is no way to rely on this compile time check to make sure someone has not started to use a new JavaScript feature unintentionally.

Other Related Issues

There seems to be a other "related" issues, but best as I can tell none that discuss this specific problem.

#41999

#18588

There does appear to a proposal that I believe would address this issue https://gist.github.com/RyanCavanaugh/702ebd1ca2fc060e58e634b4e30c1c1c. Not sure if that means other issues have already been created and closed related to this problem. Apologies if they have.

@greyepoxy
Copy link
Author

Just wanted to call out that after digging into the node types history a bit more, seems like the inclusion of lib references has been going on for much longer then I thought. For example
bigint was added Feb 23, 2019
the other references appear to have been added Feb 6, 2019 with the introduction of the first typesVersions
Not sure this really changes anything, more of calling out that unraveling the types is probably not an option at this point.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 18, 2021
@RyanCavanaugh
Copy link
Member

See also #37053

@greyepoxy
Copy link
Author

greyepoxy commented Feb 18, 2021

hmmm, @RyanCavanaugh not sure I understand how this is a duplicate of that item. The problem of test types being available in non-test files seems similar but I do not believe it is the same.

Were you thinking that the solution to that issue would address this issue as well?

@RyanCavanaugh
Copy link
Member

The "scope pollution" problem occurs in all of these contexts and has the same speculative fix in each place - some way for the transitive dependencies of types packages to not appear in your program.

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants