Question · JavaScript and React course · Module 12: React and TypeScript

useReducer Actions as Discriminated Union

Why is it best to define action types in useReducer as a discriminated union?

Answer options

  • Because TypeScript automatically narrows the payload type in each case of the reducer
  • Because discriminated union is faster at runtime
  • Because React requires type and payload fields in actions
  • Because useReducer does not work with other action types

You can check the correct answer by solving this task in the CodeWorlds game.