menu
148 tokens

Patterns and Match

Pattern matching.

Patterns and Match

  • patterns

  • refutable vs irrefutable

  • match

  • Sequence type

  • ... except for dynamic index signatures where it types as V | undefined (via dynamic.find)

  • ranges: ..

  • switch still works but match encouraged

  • let, let-else

  • if let

  • while let

  • match guards

  • No Computed Keys

  • no obj[expr] where expr is dynamic

  • destructure dynamically with { [key]: value }?

src/match.ds.ds
1enum State { Pending, Running, Complete }2declare const state: State;3 4const label = match (state) {5    State.Pending => "pending",6    State.Running => "running",7    State.Complete => "complete",8};