-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Search Terms
tuple type elements members labels names naming
Suggestion
Currently tuple types are defined like so:
// length, count
type Segment = [number, number];
I often find myself having to add labels to the elements of the tuple as a comment b/c the types themselves (number, string) don't adequately describe what the elements represent.
It would be nice if we could add labels to tuple elements using syntax similar to function parameters like so:
type Segment = [length: number, count: number];
Use Cases
Currently we use comments to describe tuples, but adding this information directly to the AST can provide additional information for tooling.
Examples
This new syntax would also be useful in return types:
function createSegment(/* ... */): [length: number, count: 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. new expression-level syntax)
bluelovers, sindresorhus, ovidiuch, aleclarson, SetTrend and 190 morecpplearner, rope-hmg, ikokostya, motss, maninak and 2 moreAnyhowStep, armano2, felixfbecker, motss and yfzheand1truong, artemjackson, AFDevMike and christiankaindl
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript