import { RuntypeBase, Static, create, Codec, assertRuntype } from '../runtype'; import show from '../show'; export const RuntypeName = Symbol('RuntypeName'); export interface Brand> extends Codec< Static & { [RuntypeName]: B; } > { readonly tag: 'brand'; readonly brand: B; readonly entity: A; } export function Brand>(brand: B, entity: A) { assertRuntype(entity); return create>( 'brand', { p: (value, _innerValidate, innerValidateToPlaceholder) => innerValidateToPlaceholder(entity, value) as any, u: () => entity, }, { brand, entity, show(needsParens) { return show(entity, needsParens); }, }, ); }