Last active
January 30, 2019 16:40
-
-
Save balanza/418522f38be8b6dfc08e5b40641e8cbe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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