Skip to content

Instantly share code, notes, and snippets.

@balanza
Last active January 30, 2019 16:40
Show Gist options
  • Save balanza/418522f38be8b6dfc08e5b40641e8cbe to your computer and use it in GitHub Desktop.
Save balanza/418522f38be8b6dfc08e5b40641e8cbe to your computer and use it in GitHub Desktop.
type Valued<T> = { value: T }
type ConfirmedMobile = Valued<string> & { status: 'confirmed' }
type UnconfirmedMobile = Valued<string> & { status: 'unconfirmed' }
type Mobile = ConfirmedMobile | UnconfirmedMobile
type User {
/* name, surname, etc */
mobile: Mobile
}
// an user with confirmed mobile
const User1 = {
name: 'Mario',
mobile: {
status: 'confirmed',
value: '123456789'
}
}
// an user with UNconfirmed mobile
const User2 = {
name: 'Luigi',
mobile: {
status: 'confirmed',
value: '987654321'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment