Skip to content

Infer result type when available in .deserialize #38

@jokull

Description

@jokull

Basically I'm having to do this:

const result = Result.deserialize<
  Extract<typeof serialized, { status: "ok" }>["value"],
  Extract<typeof serialized, { status: "error" }>["error"]
>(serialized);

But even here, because serialized is typed, we don't need to check Result shape and .

In fact ... what I want when my stack has the serialized shape is to just do this:

if (serialized.status === "ok") {
  result = new Ok(serialized.value);
} else {
  result = new Err(serialized.error);
}

So maybe I just want Result.fromSerialized or Result.new?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions