effect icon indicating copy to clipboard operation
effect copied to clipboard

how to extend tagged enum?

Open krzysztofpniak opened this issue 9 months ago • 0 comments

What is the type of issue?

No response

What is the issue?

I have an tagged enum defined as following:

type RemoteData<Success, Failure> = Data.TaggedEnum<{
  Created: {};
  Loading: {};
  Success: {data: Success};
  Failure: {reason: Failure};
}>;

interface RemoteDataDefinition extends Data.TaggedEnum.WithGenerics<2> {
  readonly taggedEnum: RemoteData<this['A'], this['B']>;
}

const RemoteData = Data.taggedEnum<RemoteDataDefinition>();

export {RemoteData};

I would like to add my own methods like $is or $match, ie. map. Example usage:

RemoteData.map(x => x + '1', RemoteData.Success({data: 'some result'})) //it should only map Success case

Where did you find it?

No response

krzysztofpniak avatar Mar 27 '25 11:03 krzysztofpniak