Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow unions within a domain like boolean to be used as discriminants #1010

Open
ssalbdivad opened this issue Jun 13, 2024 · 0 comments
Open

Comments

@ssalbdivad
Copy link
Member

Currently the following is not discriminated during traversal:

const t = type(["string"])
  .pipe((s) => s.length)
  .or(["boolean"]);

This is because boolean is being treated as a union and we don't identify that we could discriminate using domain.

It should be discriminated similarly to the existing test case "discriminable tuple union" where number is substituted for boolean:

const $ = scope({
  a: () => $.type(["string"]).pipe((s) => [...s, "!"]),
  b: ["number"],
  c: () => $.type("a|b"),
});
const types = $.export();

attest<[number] | ((In: [string]) => Out<string[]>)>(types.c.t);
const expectedSerializedMorphs =
  types.a.raw.assertHasKind("morph").serializedMorphs;

attest(types.c.raw.assertHasKind("union").discriminantJson).snap({
  kind: "domain",
  path: ["0"],
  cases: {
    '"number"': {
      sequence: { prefix: ["number"] },
      proto: "Array",
      exactLength: 1,
    },
    '"string"': {
      in: {
        sequence: { prefix: ["string"] },
        proto: "Array",
        exactLength: 1,
      },
      morphs: expectedSerializedMorphs,
    },
  },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

No branches or pull requests

1 participant