Skip to content

Instantly share code, notes, and snippets.

@jgentes
Created November 7, 2022 14:36
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/377e40af7edaaf6b9cfd20616b07d335 to your computer and use it in GitHub Desktop.
Save jgentes/377e40af7edaaf6b9cfd20616b07d335 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 = { id: "1234-1234-1234", name: "John Doe", age: 24 }

// In this case, we define CustomType as a number let myOtherUser:User = { 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