You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently TypeScript would suggest that parameter is named args_0. If it could infer the name of the parameter from the Named Tuple above, it would instead suggest increment.
Also, it is not clear what that last returned number is. With Named Return this autocompletion dialog could display newState.
Analogy
When we define a function in TypeScript, we don't skip parameter names like
typeFibonacci=(number)=> number;
instead we name the parameters
typeFibonacci=(n: number)=>number;
similarly, not just function parameters, but any place where some type is used could be assigned a name
typeFibonacci=(n: number)=>result: number;
Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript/JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
I think #28259 covers the palatable aspects of this. The other positions described here don't seem like places where adding yet another meaning of : would improve readability, and where there's already a "name" available.
Search Terms
named, named types, named return, named tuples, name array
Suggestion
Allow to name types in specific locations, similar to how function parameters or object keys have "names".
Named Return Type
Below is a React higher order component type that suggest user that the return value of the function could be called
enhancedComponent
.Named Generic Type
Named Tuples
Allow to assign names to tuple entries.
Renamed Object Keys
Allow to suggest a better naming for object keys when they are de-structured.
Editors would automatically suggest naming when de-structuring.
Use Cases
Examples
One could name function return value and parameters using generics.
(Note
newState:
andincrement:
.)Currently TypeScript would suggest that parameter is named
args_0
. If it could infer the name of the parameter from the Named Tuple above, it would instead suggestincrement
.Also, it is not clear what that last returned
number
is. With Named Return this autocompletion dialog could displaynewState
.Analogy
When we define a function in TypeScript, we don't skip parameter names like
instead we name the parameters
similarly, not just function parameters, but any place where some type is used could be assigned a name
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: