Skip to Main Content
Modern Front-End Development for Rails, 2nd Edition
book

Modern Front-End Development for Rails, 2nd Edition

by Noel Rappin
September 2022
Intermediate to advanced content levelIntermediate to advanced
410 pages
10h 7m
English
Pragmatic Bookshelf
Content preview from Modern Front-End Development for Rails, 2nd Edition

Creating Union Types

I want to start with a concept we’ve already seen, but which I want to talk about in more depth because it winds up being important for understanding other TypeScript techniques. The feature is called a union type, and we used it to create the type checking for our action types in our various reducers in Chapter 11, Managing State in React and in Chapter 12, Using Redux to Manage State.

You create a union type by combining existing types with the pipe operator ( | ). The existing types can be built-in or specific to your code. One of our union types, for example, looks like this:

 export​ type VenueAction =
  | ClearHolds
  | HoldTicket
  | InitFromProps
  | SetTicketToBuy ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Modern Front-End Development for Rails

Modern Front-End Development for Rails

Noel Rappin

Publisher Resources

ISBN: 9781680509977Errata Page