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

Can't handle recursive types #27

Open
Eduardogbg opened this issue Mar 21, 2024 · 4 comments
Open

Can't handle recursive types #27

Eduardogbg opened this issue Mar 21, 2024 · 4 comments

Comments

@Eduardogbg
Copy link

Eduardogbg commented Mar 21, 2024

Hey guys, thanks for taking on the maintenance of this important library.

There's a problem that all forks of this lib had, that is not handling recursive types at all. So you can't use any type of tree, for example. Since Typescript's type system is super powerful and supports recursive types and much more, this should be doable, but I understand that it could require a huge refactor since the original authors clearly didn't think of this.

One section of my ABI which includes typing cycle is:

    {
      "id": 3,
      "type": {
        "def": {
          "sequence": {
            "type": 4
          }
        }
      }
    },
    {
      "id": 4,
      "type": {
        "def": {
          "tuple": [
            5,
            6
          ]
        }
      }
    },
    {
      "id": 5,
      "type": {
        "def": {
          "primitive": "u128"
        }
      }
    },
    {
      "id": 6,
      "type": {
        "def": {
          "variant": {
            "variants": [
              {
                "fields": [
                  {
                    "type": 0,
                    "typeName": "AccountId"
                  }
                ],
                "index": 0,
                "name": "Account"
              },
              {
                "fields": [
                  {
                    "type": 3,
                    "typeName": "Vec<(SplitFraction, SplitNode)>"
                  }
                ],
                "index": 1,
                "name": "Nested"
              }
            ]
          }
        },
        "path": [
          "mufi_splits",
          "splits",
          "split_tree",
          "SplitNode"
        ]
      }
    },

And the SplitNode enum could easily be defined in TypeScript as something like

type SplitNode = string | [number, SplitNode][]

I'm trying to patch the lib but it would be great to have any help whatsoever.

Thanks

@goastler
Copy link
Member

Hi @Eduardogbg , thanks for the issue! We're aware of this problem and are experiencing it ourselves unfortunately. We've got an overhaul of typechain in the pipeline, but it's nowhere near ready yet. In the meantime, if you do produce a patch I'd be happy to review and merge it in :)

@Eduardogbg
Copy link
Author

Well if you guys are already on it — having way more context than I already have — I guess I'll just keep a hacky patch that works for my specific contract to keep the stack from overflowing and manually edit the generated files so it works just enough.

Good luck with this work though, it's fundamental for the ecosystem. Hope you guys have a grant for that.

@goastler
Copy link
Member

Would I be able to get a copy of your hack? Would be great info to guide development :)

We don't have a grant currently, and are only maintaining this library because it is pivotal to our product. However, we were thinking of applying for a grant. Would you be willing to support us in that endeavour? (I.e. a message of support on a forum post)

@Eduardogbg
Copy link
Author

Ok, when I get the chance, I can create a fork with an explanation. And I would be glad to show support. This is important, and it seems no one else is maintaining it anymore.

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

No branches or pull requests

2 participants