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

Narrowing a morph within a single type preserves the type-level morph representation #970

Open
ssalbdivad opened this issue May 24, 2024 · 0 comments

Comments

@ssalbdivad
Copy link
Member

This test case is currently commented out because it fails at ark/type/__tests__/narrow.test.ts:115

it("narrows the output type of an morph within a single type", () => {
  const t = type("string")
    .pipe((s) => `${s}!`)
    .narrow((s): s is "foo!" => s === "foo!");

  attest<Type<(In: string) => Out<of<"foo!", Narrowed>>>>(t);
});

It is actually inferred as:

type Actual  = Type<of<"foo!", Narrowed>

Because includesMorphs in ark/schema/roots/morph.ts can't identify a morph within a single type.

To resolve this issue, includesMorphs would likely have to recurse directly to find a morph AST, or _distill would need to return a context of some sort that includes the distilled type as well as other info like whether a morph was encountered.

This change could be expensive in terms of static perf, so benchmarks should be run to ensure the cost is acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

1 participant