Skip to content

Instantly share code, notes, and snippets.

@ericwooley
Last active Mar 19, 2021
Embed
What would you like to do?
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