type-plus
Version:
Provides additional types for TypeScript.
23 lines • 825 B
TypeScript
import type { Widen } from '../utils/index.js';
import { typeSym, valueSym } from './constants.js';
/**
* Create a "branded" version of a type.
* TypeScript won't allow implicit conversion to this type
*/
export type Brand<B extends string, T = never> = [T] extends [null] | [undefined] | [symbol] | [void] ? Branded<B, T> : Branded<B, T> & T;
/**
* A branded type of `B` with value of `T`.
*/
export interface Branded<B extends string, T> {
[typeSym]: B;
[valueSym]: T;
}
/**
* Creates a brand creator with the specified type.
*/
export declare function brand<B extends string>(type: B): <T>(subject: T) => Brand<B, Widen<T>>;
/**
* Creates a branded value of specified type.
*/
export declare function brand<B extends string, T>(type: B, subject: T): Brand<B, Widen<T>>;
//# sourceMappingURL=brand.d.ts.map