menu
110 tokens

Narrowing

Type narrowing as usual.

Narrowing

  • type narrowing as usual, narrowing is just doing runtime type checking
  • instanceof, typeof, is
  • typeof in type position
  • is for type queries
  • instanceof for classes
  • match narrowing
src/narrowing.ds.ds
1type Event =2    | { kind: "ready"; port: uint16 }3    | { kind: "closed"; reason: string };4 5function describe(event: Event): string {6    if (event.kind == "ready") {7        return `listening on ${event.port}`;8    }9 10    event.reason11}