-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestoneSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
π Search Terms
named object property tuple type lookup
β Viability Checklist
- 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, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
β Suggestion
Developers sometimes accidentally use []
to declare a type instead of {}
. Later, when they try to access a property by string name, the error message doesn't indicate that it's a []
tuple instead of {}
object. Can we get a specific error message for that example?
π Motivating Example
The following Label
type alias seems to describe a reasonable tuple at first. But later on we see that the developer might have meant to describe an object type.
type Label = [
text: string;
];
declare const label: Label;
label.text;
// Property 'text' does not exist on type 'Label'.
How about a specialized diagnostic indicating 'Label'
is a tuple?
Property 'text' does not exist on type 'Label'.
'Label' is a tuple type with numeric keys, not an object type with string keys.
...bikeshedding needed on that message π€
π» Use Cases
- When a developer meant to write an object type but used a tuple instead
- When a developer misread a tuple type as an object type
- When a developer is new to tuples and/or types, and confused the two's syntaxes
Example real-world developer pain point (posted with permission): https://twitter.com/yagiznizipli/status/1736762337716039967
robpalme, fatcerberus and Haroenv
Metadata
Metadata
Assignees
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestoneSuggestionAn idea for TypeScriptAn idea for TypeScript