-
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
Type subscope for local type aliases #41470
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Comments
In the meantime you can make use of the long forgotten art of adding comments. :-) |
Here are my quick thoughts on why comments aren't sufficient:
|
Seems similar to #23188, though it seems like here you have an anonymous namespace with a single exported type. |
RyanCavanaugh
added
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
labels
Nov 12, 2020
5 tasks
5 tasks
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Search Terms
type scope, type iife
Suggestion
A syntax that allows for a type subscope (like a js IIFE).
Use Cases
When constructing complex types, they are often not very readable without breaking them up into multiple type aliases. However, this means that you have to pass the type aliases through, along with their constraints, and it can become even less readable.
Examples
Basic examples of the concept / suggested syntax
Example of applying this to a real-world type
Consider the traditional approach in the following type:
This isn't very readable; it might help to extract some of it to type aliases:
That doesn't look great, pollutes the type scope, and has a bit of
extends
boilerplate.With this proposal, you could write:
Or, a terser variant:
While we're all used to nested conditional types, if you saw the equivalent of the original type definition in runtime code, you would likely agree that it should be refactored.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: