I possess a type known as ElementCategory that comprises an array of elements with varying types.
Each element is equipped with numerous properties, including a type
property of the type ElementType
, which serves as an enum listing all available element types, and a variable data
property dependent on the specific type
of the element.
A mapped type dubbed ElementsData
is in place to ideally receive the element type and return the corresponding data type exclusively for that specific element type (however, the code below doesn't exhibit this behavior):
[Code Snippet]
My inquiry is: How can I ensure that the ElementType
passed to the type
property matches the one sent to ElementsData
?
If you check out the Repro link I've generated to exemplify the issue. Hovering over the data property during element creation reveals it's not accurately detecting the data type based on the element type, as anticipated.
Note: Even after attempting to make 'Element' generic, I was obliged to incorporate a generic type annotation to the elements
array, which didn't yield the intended outcome since forcing a single element type in the array wasn't my aim. Did I overlook something?