-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Allow disabling ambient types #54123
Comments
Sounds like a duplicate of #50424. |
It's not really clear how you could make this work in a general case. Consider the case where you have some generic type with a type constraint: type F<T extends Foo> = ... Let's say the library code instantiates F with a global type that you've augmented to match Foo, but which previously wouldn't have matched. Presumably, now this has to be a type error, but it shouldn't be an error because it's code that depends on an invariant that the library itself set up in the first place. That seems really awkward and also not possible for you to fix on your side. We've looked at the problem of global pollution a lot and not yet found any solutions that don't incur these or other similar kinds of problems. See also #31894 and related discussions |
Thanks, I'm happy to close this off as a duplicate if you'd like. I realise that this is a hard problem to solve, and I understand the issues that you've raised here. Thinking about other rules with similar problems, |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Suggestion
I understand that this is something that there will be a range of opinions on.
What I'd like is an option to restrict ambient types so that even if a library has shipped with ambient types, they aren't exposed. Ideally, this would also prevent those libraries from modifying global types.
🔍 Search Terms
I searched for:
Related:
Possibly related:
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
An option in TS Config to prevent library-provided ambient types from polluting the global namespace.
📃 Motivating Example
The rationale for this:
React
and some rely on the ambient types.Further, I commented on this issue (related) and noted that we've actually encountered bugs because some of these libraries also modify global types.
💻 Use Cases
As an example, we hit an issue last year where global types were being modified by libraries, which caused type issues that were hard to diagnose and fix.
The text was updated successfully, but these errors were encountered: