Slide 23
Slide 23 text
const fooAction = (payload: {value: string}) => {
return {
type: "FOO" as const,
payload
}
}
const barAction = (payload: {value: string}) => {
return {
type: "BAR" as const,
payload
}
}
type ActionTypes = ReturnType | ReturnType;
// "FOO" | "BAR"
const reducer = (state: State, action: ActionTypes) => {
switch (action.type) {
case "BAZ": // Error '"BAZ"' is not comparable to type '"FOO" | "BAR"'
...
}
}