Improve parser error on mapped type with additional property declarations #45089
Closed
5 tasks done
Labels
Experience Enhancement
Noncontroversial enhancements
Fix Available
A PR has been opened for this issue
Suggestion
An idea for TypeScript
Milestone
Suggestion
Properties generators [Ed: Mapped types] require separate type definition. Is this really a requirement by design limitations? It's weird for me that I must to merge two types to get type I actually want. Also, depending on where the
[foo in Foos]: Bar
part is placed, it gives two different, but both hard to understand error - it would be nice to have easy to understand error at least, even if separate type is required.🔍 Search Terms
Properties generation. Mapped types.
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
Make properties generator thing work if it's amongst other properties. There should be check that generated property names are other than properties defined alongside.
If not possible (due to design limitations or something), make it return easy to understand error.
📃 Motivating Example
The 17th line
} & {
seems just a burden.Output
Compiler Options
Playground Link: Provided
Other examples:
💻 Use Cases
Its not important issue. Its just quality of life, something rarely used could look a bit better. Workaround is just separate the property generator and join with others. What's nice about the workaround is that it report error if properties generated overlap with properties defined attached (i.e, you can add
'model'
intoPlaceTypes
, and there is proper error).The text was updated successfully, but these errors were encountered: