Skip to content

Instantly share code, notes, and snippets.

@dcolthorp
Last active July 6, 2023 23:00
Show Gist options
  • Save dcolthorp/aa21cf87d847ae9942106435bf47565d to your computer and use it in GitHub Desktop.
Save dcolthorp/aa21cf87d847ae9942106435bf47565d to your computer and use it in GitHub Desktop.
/** Used by Flavor to mark a type in a readable way. */
export interface Flavoring<FlavorT> {
_type?: FlavorT;
}
/** Create a "flavored" version of a type. TypeScript will disallow mixing flavors, but will allow unflavored values of that type to be passed in where a flavored version is expected. This is a less restrictive form of branding. */
export type Flavor<T, FlavorT> = T & Flavoring<FlavorT>;
/** Used by Brand to mark a type in a readable way. */
export interface Branding<BrandT> {
_type: BrandT;
}
/** Create a "branded" version of a type. TypeScript won't allow implicit conversion to this type */
export type Brand<T, BrandT> = T & Branding<BrandT>;
@unional
Copy link

unional commented Feb 11, 2019

Thanks!

Going in: unional/type-plus#18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment