Effect CommunityEC
Effect Community2y ago
2 replies
dmmulroy

Creating Custom Brands with Schema in TypeScript

Is there a way to create brands like this with schema?

declare const EntityEventIdSymbol: unique symbol;

const EntityEventId = S.String.pipe(
  S.startsWith('entity_evt_' as const),
  S.brand(EntityEventIdSymbol),
);

// wanted type: type EntityEventId = `entity_evt_${string}` & Brand.Brand<typeof EntityEventIdSymbol>;
// inferred: type EntityEventId = string & Brand.Brand<typeof EntityEventIdSymbol>
type EntityEventId = S.Schema.Type<typeof EntityEventId>;
Was this page helpful?