Skip to content

Instantly share code, notes, and snippets.

@gbishop
Created July 27, 2017 14:48
Show Gist options
  • Save gbishop/f1bdcdc8cafe673353c506fd8185410a to your computer and use it in GitHub Desktop.
Save gbishop/f1bdcdc8cafe673353c506fd8185410a to your computer and use it in GitHub Desktop.
typescript discriminated union question
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