Skip to content

Instantly share code, notes, and snippets.

@LFSCamargo
Last active February 7, 2019 01:38
Show Gist options
  • Save LFSCamargo/65c44de12a3c4f087a121fd9ab088ed6 to your computer and use it in GitHub Desktop.
Save LFSCamargo/65c44de12a3c4f087a121fd9ab088ed6 to your computer and use it in GitHub Desktop.
Type Composing example
// 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: 'foo@foo.com',
password: '123',
users: [...],
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment