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

Support recursive generics in 2.0 release candidate #1082

Open
ssalbdivad opened this issue Aug 6, 2024 · 0 comments
Open

Support recursive generics in 2.0 release candidate #1082

ssalbdivad opened this issue Aug 6, 2024 · 0 comments

Comments

@ssalbdivad
Copy link
Member

Recursive generics work at a type-level, but will crash at runtime.

We need to introduce a mechanism for tracking instantiated args so we can avoid infinitely recursing in these cases.

Also would mean re-enabling these tests in generic.test.ts

it("self-reference", () => {
  const types = scope({
    "alternate<a, b>": {
      // ensures old generic params aren't intersected with
      // updated values (would be never)
      swap: "alternate<b, a>",
      order: ["a", "b"],
    },
    reference: "alternate<0, 1>",
  }).export();
  attest<[0, 1]>(types.reference.infer.swap.swap.order);
  attest<[1, 0]>(types.reference.infer.swap.swap.swap.order);
  const fromCall = types.alternate("'off'", "'on'");
  attest<["off", "on"]>(fromCall.infer.swap.swap.order);
  attest<["on", "off"]>(fromCall.infer.swap.swap.swap.order);
});
it("self-reference no params", () => {
  attest(() =>
    scope({
      "nest<t>": {
        // @ts-expect-error
        nest: "nest",
      },
    }).export()
  ).throwsAndHasTypeError(writeInvalidGenericArgsMessage("nest", ["t"], []));
});
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