I am currently developing a React Native app using TypeScript.
As part of my development, I am creating a handler with a switch case structure like the one below:
export const handleMessageData = (dispatch: Dispatch, messageData: FCMMessage): void => {
const { type, message_data } = messageData;
const data = camelizeKeys(JSON.parse(message_data));
switch (type) {
case conditionOne:
data.consumer = data.consumer.uuid;
setHouses({ entities: { houses: { [data.uuid]: data } } });
// ... more cases
default:
// ... do stuff
}
};
In each case, I am aware of the type of data
. How can I explicitly declare this in TypeScript?
Here's some pseudo code to illustrate what I'm trying to achieve:
case conditionOne:
data: MyType;
data.consumer = data.consumer.uuid;