Skip to content

Instantly share code, notes, and snippets.

@ericwooley
Last active March 19, 2021 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericwooley/6e7722104d42bb87cd42fa1e13ef4cd0 to your computer and use it in GitHub Desktop.
Save ericwooley/6e7722104d42bb87cd42fa1e13ef4cd0 to your computer and use it in GitHub Desktop.
Extract explanation
// states of h2o
type h2o = 'water'|'steam'|'ice'
// states of h2o that will pass through a filter
type filter = 'water'|'steam'
// Extract non solid forms of h2o
type nonSolidH2o = Extract<h2o, filter>
// these are fine, they are not solid
const water: nonSolidH2o = 'water'
const steam: nonSolidH2o = 'steam'
// ice should error, because it cannot pass through a filter
// @ts-expect-error
const ice: nonSolidH2o = 'ice'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment