For JSX Attributes, map over unions of props for contextual types#17790
Conversation
…on member; rather than all of them
| const attributeName = node.parent.name.escapedText; | ||
| if (attributesType.flags & TypeFlags.Union) { | ||
| // The attribute may fulfill any of the members of the union | ||
| return getUnionType(compact(map((attributesType as UnionType).types, t => getTypeOfPropertyOfType(t, attributeName)))); |
There was a problem hiding this comment.
Use mapDefined instead of compact(map()).
|
Do you know why |
|
@Andy-MS Since it's a union and the property only exists on one option of the union, the property gets marked as |
|
Is there any reason why JSX should differ from object literals here? |
|
@Andy-MS Thanks for the prompt - I hadn't realized we were doing something slightly differently for non-jsx-related contextual types. Elsewhere we were using |
| InferenceShouldNotProduceAny({ data: 2, convert: n => "" + n }); | ||
|
|
||
|
|
||
| const f1 = <InferenceShouldNotProduceAny data={"1"} />; |
There was a problem hiding this comment.
This is tiny, but a positive name like InferenceShouldProduceNumber would be better.
This way an individual attribute can fulfill any of them, rather than failing to get a contextual type unless it fulfills all of them.
Fixes #17427