Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgentes/fe89c85a33db3932c6008c0f8cb19dee to your computer and use it in GitHub Desktop.
Save jgentes/fe89c85a33db3932c6008c0f8cb19dee to your computer and use it in GitHub Desktop.
// 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