Created
November 7, 2022 14:37
-
-
Save jgentes/fe89c85a33db3932c6008c0f8cb19dee 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 User can have an ID which is either a number or a string | |
type User<CustomType extends number | string> = { | |
id: CustomType | |
name?: string | |
age?: number | |
} | |
// In this case, we define CustomType as a string | |
let myUser: User<string> = { | |
id: '1234-1234-1234', | |
name: 'John Doe', | |
age: 24, | |
} | |
// In this case, we define CustomType as a number | |
let myOtherUser: User<number> = { | |
id: 1234, | |
name: 'Jane Seymore', | |
age: 48, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment