-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Scoped types #56310
Comments
I'm confused by the motivating example - surely the return type of |
Feel like this has been suggested before... If not then #7061 is related |
I'm confused. The function-local |
I suppose my example was a poor one. Though, we often write functions that use intermediate types different than the return type. Right now, you have to define those types on a module's top-level scope. Even if they are not exported, they are visible to the entire module. I am proposing the ability to define types with deeper scopes, such as a function's scope. This approach produces much more intentional code as it is clear where a type is used and for what it is used. You may say that a better solution to "scope" types is by splitting a module into multiple modules and only defining the type in the necessary module. But should TypeScript, a language, be this opinionated? |
Could you edit the motivating example to include more motivation and fewer distractions?
Function-scoped types are already supported. Can you demonstrate otherwise? Or describe what about the current support is insufficient? |
Which you can, so what is this about? I don't see anything new, at all, being proposed here. |
π Search Terms
scope scoped scopes type types
β Viability Checklist
β Suggestion
It would be great if you could scope types. Types could be scoped like everything else with
{ SCOPE }
.π Motivating Example
Code can be written more intentionally. If a type is meant to only be used within a specific function, for example, it should be defined in that function.
π» Use Cases
This would allow developer to write clearer and more intentional code. A scoped type would clearly demonstrate that it is only used within the scope it is defined.
The language does not demonstrate how and where a type is used.
There are no alternatives at the moment.
The text was updated successfully, but these errors were encountered: