Open1
Valibotのbrandを外から与えられるようにする
export interface BrandAction<TInput, Brand extends TInput>
extends BaseTransformation<TInput, Brand, never> {
/**
* The action type.
*/
readonly type: "branded";
/**
* The action reference.
*/
readonly reference: typeof branded;
}
export function branded<TInput, Brand extends TInput>(
brandOf: Brand,
): BrandAction<TInput, Brand> {
return {
kind: "transformation",
type: "branded",
reference: branded,
async: false,
"~run"(dataset) {
return dataset as SuccessDataset<Brand>;
},
};
}
function brandOf<T>(): T {
return undefined as T;
}
type X = Tagged<string, "X">;
import * as v from "valibot";
const XSchema = v.pipe(v.string(), branded(brandOf<X>()));
type Output = v.InferOutput<typeof XSchema>;