-
Notifications
You must be signed in to change notification settings - Fork 363
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
fix: type generation for nested tuples #5395
fix: type generation for nested tuples #5395
Conversation
Thank you. I believe if ... (a) it works on the problematic metadata, ... then we should be ok. Will dive through the logic. (There are some small linting issues CI picked up, it is a bit pedantic...) |
Regarding (a), this is the output it generates:
Focusing on the
So we have...
But we don't have:
... That's a lot of alternatives.. Would these be expected to be present in the generated type? |
Where the alternatives help and are critical... Think about a simple enum Sample {
Alice(AccountId32),
Bob(u32)
} When it generates, it should look more-or-less like So basically when using the argument, you can pass either -
The second option is what makes things easier to use since the API will convert to the correct type. Without having that the user always has to manually do the (On to any: it should in this case be something like |
So summarize my answer above - it would be great if the alternatives are supplied, i.e. users can have a mixture of stuff-already-created and pure JS objects for all. Alternatives are all to make it easier to use with TS complaining about type mismatches. (Since the API does convert from anything reasonable to the correct type) |
Right, that makes sense. I just checked that this PR creates the same output as the unmodified code, when run on a metadata that does not contain nested tuples. Given that the output for nested tuples seems to be correct (even though incomplete), and that the failing type generation is blocking us, would you be open to merging this PR and opening an issue for generating the alternatives? |
Happy to merge as-is since it does move use into a much better spot, although it is incomplete. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy with the output as-is. (Also tested the changes with yarn build:metadata
and it is equivalent)
Just needs some small adjustments to make CI happy.
Thanks! I pushed a fix for the formatting and made an issue for the missing alternatives: #5399 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Addresses #5383 .
Without this,
setImports
fails for the input"[ITuple<[InterbtcPrimitivesCurrencyId, InterbtcPrimitivesCurrencyId]> | [InterbtcPrimitivesCurrencyId | { Token: any } | { ForeignAsset: any } | { LendToken: any } | { LpToken: any } | { StableLpToken: any } | string | Uint8Array, InterbtcPrimitivesCurrencyId | { Token: any } | { ForeignAsset: any } | { LendToken: any } | { LpToken: any } | { StableLpToken: any } | string | Uint8Array], AccountId32 | string | Uint8Array]"
.I think this example can be simplified to
"[ITuple<[u32, u32]>, u32]"
. Due to the<
of the tuple, the wrong branch ofsetImports
was taken. Swapping the order of the branches causes the right branch to be taken, but the regex-based splitting then fails -- the regex would returnITuple<[u32, u32
due to the nested[]
. As an aside, the regex also seemed to be incorrect for the[a|b, c|d]
type: it would return['a', 'b,c', 'd']
, i.e. not splittingb,c
. ThesplitAlternatives
function is meant to address these issues.When reviewing, please also note the change of
type.startsWith('[')
totype.includes('[')
. All in all I am not 100% confident of the correctness of this pr. The type generation no longer throws an error, but I don't know whether or not the output is correct, and whether the change works for all possible types.