Last active
February 7, 2019 01:38
-
-
Save LFSCamargo/65c44de12a3c4f087a121fd9ab088ed6 to your computer and use it in GitHub Desktop.
Type Composing example
This file contains 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
// working with pipes and type | |
type Fruit = "orange" | "banana" | "strawberry"; | |
// working with types and functions | |
type EatFruitFunction = (fruit: Fruit) => void; | |
// typing objects using type | |
type User = { | |
username: string, | |
email: string, | |
password: string, | |
} | |
type UserList = { | |
users: User[] | |
} | |
// Composing `n` types | |
type Composed = User & UserList & { | |
// Here you can write your other props | |
example: Object | |
}; | |
/** | |
How this will look like on the end: | |
{ | |
example: {}, | |
username: 'foo', | |
email: '[email protected]', | |
password: '123', | |
users: [...], | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment