Skip to content

.tip

· one of the small things

unknown at the boundary, never any

any switches the type checker off for everything it touches. unknown accepts anything as well, but you can't use it until you've narrowed it, and at a boundary that's the whole point.

function parse(input: unknown): Config {
  if (!isConfig(input)) throw new Error("bad config");
  return input; // narrowed
}

JSON.parse results, fetch responses, event payloads and environment variables are all unknown until proven otherwise.

typescript