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

Exhaustive Checking with never

What happens in TypeScript if you add a new variant to a discriminated union but don't handle it in a switch with assertNever?

Answer options

  • TypeScript will report a compilation error in the default case
  • The application will stop working at runtime
  • React will automatically add handling for the new variant
  • The code will compile without issues

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