Skip to content

Support recursive generics in 2.0 release candidate #1082

Closed

Description

@ssalbdivad

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"], []));
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done (merged or closed)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions