sloppy_diffuser,

There is support for this in Effect as another implementation.

effect.website/docs/guides/…/pattern-matching

towerful,

Just have default throw an error? Then, if you add a value to the string union (hopefully) your tests will highlight it isnt handled.

Equally, for such a simple switch, surely a map is better?
But i rarely find myself using switches.
I find ifs with early returns cleaner. Allows for variable creation during execution (which my tslint complains about)

sbv,

I really appreciate compile errors in this scenario. In Rust the compiler will freak out when there are missing enum variants in a match. Tests are great, but compiler errors don’t rely on exhaustive and properly written tests.

arendjr,

Generally, I would recommend against throwing in the default case, since it will actually reduce your type safety (exceptions bypass all your other types). But I learned that with another clever trick this can be avoided, giving both runtime and compile time safety: exploringjs.com/tackling-ts/ch_enums.html#exhaust…

  • All
  • Subscribed
  • Moderated
  • Favorites
  • typescript@programming.dev
  • DreamBathrooms
  • magazineikmin
  • thenastyranch
  • Youngstown
  • mdbf
  • rosin
  • slotface
  • InstantRegret
  • khanakhh
  • Durango
  • kavyap
  • osvaldo12
  • tacticalgear
  • GTA5RPClips
  • megavids
  • ngwrru68w68
  • everett
  • tester
  • ethstaker
  • cisconetworking
  • cubers
  • modclub
  • provamag3
  • anitta
  • normalnudes
  • Leos
  • JUstTest
  • lostlight
  • All magazines