Created
July 27, 2017 14:48
-
-
Save gbishop/f1bdcdc8cafe673353c506fd8185410a to your computer and use it in GitHub Desktop.
typescript discriminated union question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface HomeView { | |
view: 'home'; | |
} | |
export interface BookView { | |
view: 'book'; | |
link: string; | |
page: number; | |
} | |
interface FindView { | |
view: 'find'; | |
query?: string; | |
} | |
interface ChooseView { | |
view: 'choose'; | |
query?: string; | |
} | |
interface YourFavoritesView { | |
view: 'your-favorites'; | |
} | |
interface ErrorView { | |
view: 'error'; | |
} | |
interface SettingsView { | |
view: 'settings'; | |
} | |
type View = HomeView | BookView | FindView | ChooseView | YourFavoritesView | ErrorView | SettingsView; | |
// How can I get the type for View.view without creating this trash variable? | |
let foo: View; | |
type ViewName = typeof foo.view; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment