2023-08-03 08:01:01 +00:00
|
|
|
/**
|
|
|
|
* A module for utility types that could be used in pretty much every module.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows one to create a type that is stored as an underlying type but is distinct from it in the
|
2023-08-03 08:48:42 +00:00
|
|
|
* type system. This is also sometimes known as a "newtype".
|
2023-08-03 08:01:01 +00:00
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* // Creates a distinct `UUID` type from a `string` which can then be expected and only passed
|
|
|
|
* // with either a `UUID` constructor or a value that comes from elsewhere as a constructed `UUID`.
|
|
|
|
* type UUID = Distinct<"UUID", string>;
|
|
|
|
* function UUID(uuid: string): UUID {
|
|
|
|
* return uuid as UUID;
|
|
|
|
* }
|
|
|
|
*/
|
2023-08-03 08:31:15 +00:00
|
|
|
export type Distinct<Tag, Type> = Type & {
|
|
|
|
readonly __distinct_tag: Tag
|
|
|
|
}
|