-
Notifications
You must be signed in to change notification settings - Fork 354
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: Generate custom type definitions #4224
Conversation
@@ -2,8 +2,6 @@ | |||
|
|||
/* eslint-disable sort-keys */ | |||
|
|||
import type { Definitions } from '../../types'; |
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.
I removed this import because the definitions are type-asserted on usage anyway and the import doesn't resolve when the file is outside the polkadot-js/api
package: https://github.com/polkadot-js/api/blob/master/packages/typegen/src/fromDefs.ts#L29
Thank you. So the missing imports needs to come from So this means that this file generated should actually augment to that location (to share imports) via declare module at the top of the file. (for old-style definitions the augmented path is So where you see the above issues, if you just change to |
This PR generates the same type definitions in two files:
Both of these files have the same import errors seen in the screenshot above.
I just checked The errors are present in the types file itself, not in the files importing generated types. |
Ok, it seems the The You can also see why the InterBtc ones are not dropped, and thus creating the above issue - node_template also won't work as it stands. For an alignment fix, change |
I tried both and only rebasing off Custom RPCs are not picked up though - I only checked now |
Yes, RPCs are not yet with metadata definitions. So for those custom types are needed. |
I took a brief look last night, I think it looks good. Will give a proper look-over and merge in a short-while. |
There are still two issues to fix I think:
|
On both these points, I'd rather keep the interfaces/lookup types split, it is cleaner for manual vs automagic. (Which is why it is done that way in the API, i.e. you can see where it comes from) |
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.
Code looks spot-on. Would just adjust the lookup generated definitions.ts
and types.ts
naming to not have a conflict, but apart from that it is clean.
This pull request introduces 1 alert when merging daa4daa into 52accf6 - view on LGTM.com new alerts:
|
Generating separate lookup types was easy, but I've not had success finding a place to add their import. The new
createImports works based on the definitions, not the types. There's currently some types that are already being imported from In files like
but |
At least for usage, something like this to tell TS to augment will be needed - https://polkadot.js.org/docs/api/examples/promise/typegen#typescript-config not sure that moves you forward, will have to take a peek. |
Ok, I see how I adjusted this - for instance So it needs to be something like - '@polkadot/types/augment': {
lookup: {
...lookupDefinitions,
...userLookupDefinitions
}
}, And then we need to pass in the user definitions. You are right in that it only imports the in-tree stuff, so that needs to be adjusted with the additional new definitions. The alternative would be for the user-from-metadata to not augment |
It should be done now - no errors left after typegen is run. I'll run some integration tests on the generated interfaces tomorrow to make sure all is good. After this is merged I'll update the CLI arguments in this snippet in the docs. Let me know if there are other places that need updating too. |
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.
Thanks an absolute million for this - it has been at the back of my mind (since 6.0 went out the door), but just never had a gap to attack.
This really helps all teams out there and (while I may have neglected this), it a critical piece.
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. |
A first attempt at fixing #4213. I wasn't sure where exactly to output lookup types, so I modified
polkadot-types-from-def
as a proof-of-concept:polkadot-types-from-chain
, so CLI logic is refactoreddefinitions.ts
file from a v14 metadata file instead of using manual definitions. This means any manual type definitions would be overwrittendefinitions.ts
) unchanged, and produces decorated types indefault/types.ts
as beforeThe resulting
definitions.ts
file looks like this:polkadot-types-from-chain
is not changed because it is now able to find the types frominterfaces/default/types.ts
to resolve imports in the api interface files.There is one error left in this approach, which is that in
interfaces/default/types.ts
pallet-specific types fail to be resolved for custom pallets. For instance,OrmlTokensModuleCall
, which comes from an external pallet, is successfully resolved. I'm not very knowledgeable about Substrate but maybe this has to do with our pallets or runtime needing to make these types public somehow?