import { RuntypeBase, Static, create, Codec, assertRuntype } from '../runtype';
export type ConstraintCheck> = (x: Static) => boolean | string;
export interface Named>
extends Codec> {
readonly tag: 'named';
readonly underlying: TUnderlying;
readonly name: string;
}
export function Named>(
name: string,
underlying: TUnderlying,
): Named {
assertRuntype(underlying);
const runtype: Named = create>(
'named',
{
p: (value, _innerValidate, innerValidateToPlaceholder) => {
return innerValidateToPlaceholder(underlying as any, value);
},
u: () => underlying,
},
{
underlying,
name,
show() {
return name;
},
},
);
return runtype;
}