Provided: Reducer only accepts one of the following actions:
interface ItemAction {
type: 'ADD_TODO'|'DELETE_TODO'|'TOGGLE_TODO',
id: number
}
interface QueryAction {
type: 'SET_QUERY',
query: string
}
I anticipate that the reducer code will resemble something like this:
if (action as ItemAction) {
console.log(action.id); // TypeScript recognizes that "id" is accessible here
} else {
console.log(action.query); // TypeScript recognizes that action belongs to type QueryAction and thus "query" is accessible here
}
How can I achieve this using TypeScript?