Here is what I currently have:
type AppDisplay = "MainMenu" | "Game" | "GameOver";
interface AppState {
appDisplay: AppDisplay
}
const initialAppState : AppState = {
appDisplay: "MainMenu"
}
type ActionType = {
type: "DisplayMenu" | "DisplayGame" | "DisplayGameOver";
}
const appStateReducer = (state : AppState, action : ActionType) => {
switch (action.type) {
case "DisplayMenu":
return {
appDisplay: "MainMenu"
}
case "DisplayGame":
return {
appDisplay: "Game"
}
case "DisplayGameOver":
return {
appDisplay: "GameOver"
}
}
}
The issue with the code above arises from the fact that the assignments in appStateReducer are treated as type String instead of being recognized as type AppDisplay by TypeScript. How can I enforce that appDisplay can only be assigned values of "Game", "GameOver", or "MainMenu"?