Last active
July 6, 2023 23:00
-
-
Save dcolthorp/aa21cf87d847ae9942106435bf47565d to your computer and use it in GitHub Desktop.
This file contains 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
/** 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>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!
Going in: unional/type-plus#18