I am trying to type an API, that can be called with multiple messages. Depending on the message (string), the data parameter’s type and response’s type are different. I am setting this up using generics. In theory I think this should work, and when I hover over the variables the generic types are shown correctly, but they are not narrowed down to the correct type: if I switch depending on the message, the data object is still a tuple of all possible data types, and so is the response.
What can I do to narrow the type of the data object and return type in the switch statements?