Skip to content

Instantly share code, notes, and snippets.

@balanza
Last active February 1, 2019 08:20
Show Gist options
  • Save balanza/f7e927d40d8f8ed51f9609fa1d1877d5 to your computer and use it in GitHub Desktop.
Save balanza/f7e927d40d8f8ed51f9609fa1d1877d5 to your computer and use it in GitHub Desktop.
type ConfirmedMobile = string & { __random_transparent_property: never }
type UnconfirmedMobile = string & { __another_random_transparent_property: never }
type CertifiedMobile = string & { __again_random_transparent_property: never }
type Mobile = // ConfirmedMobile | UnconfirmedMobile | CertifiedMobile :)
ConfirmedMobile
| UnconfirmedMobile
| CertifiedMobile
const printString = (p: string) => console.log(`print String ${p}`)
const printConfirmedMobile = (p: ConfirmedMobile) => console.log(`print ConfirmedMobile ${p}`)
printString('foo')
// ^^^ ok
printConfirmedMobile('foo')
// ^^^ compilation error: cannot assign 'foo' to type ConfirmedMobile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment