Effect CommunityEC
Effect Community4mo ago
3 replies
Janosch

Issues with Branded Types and Optional Options in Effect Typescript Library

I might have found a few bugs with Options. The first thing is with branded types. I want to use Options.text and brand it. Like this:

type Name = string & Brand.Brand<'Name'>;
const Name = Brand.nominal<Name>();

const name = Options.text('name').pipe(
  Options.withAlias('n'),
  Options.withSchema(Schema.NonEmptyString.pipe(Schema.fromBrand(Name))),
  Options.repeated,
  Options.optional,
);

error: InvalidArgumentException: only single options can be variadic

If I move the Options.withSchema after the Options.repeated and turn it into an Array like this:

type Name = string & Brand.Brand<'Name'>;
const Name = Brand.nominal<Name>();

const names = Options.text('name').pipe(
  Options.withAlias('n'),
  Options.repeated,
  Options.withSchema(
    Schema.mutable(Schema.Array(Schema.NonEmptyString.pipe(Schema.fromBrand(Name)))),
  ),
  Options.optional,
);

passing no Option to the CLI is not Option.none as I'd expect but
{
  "_id": "Option",
  "_tag": "Some",
  "value": []
}

an empty array. I'd expect an empty array when an option is actually set but with no value.

Am I missing something?
Was this page helpful?