-
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
7.x typegen configuration (migration from 5.1.1) #4481
Comments
I managed to find a solution by looking at #4224 and #4213 If anyone else is running into this:
I noticed the new |
Question: considering the types are now being fetched from the chain, why does the |
Happy you got it sorted, nice write-up above. The input is still useful,
I do see your point though, some teams may just supply an empty file here when they have no need for the above. If somebody would like to make it optional when |
I still noticed that if no input definitions are passed, the only types that are generated come in the form |
Yes, it is very Java-ish, actually on purpose since the "short names" actually got a lot of teams in trouble as soon as it starts overlapping between pallets. so it basically uses the full path as specified in the metadata. As long as it remains the default and short-names are aliasses (assuming theye are no conflicts), I guess we could go crazy on aliasses. Example - // actual path in the metadata (the type params are only added in _some_ case, e.g. when conflicts)
// polkadot_primitives::v1::signed::UncheckedSigned
export interface PolkadotPrimitivesV1SignedUncheckedSigned extends Struct {
// lots of stuff goes here
...
}
// all aliases, checked for conflicts
// v1::signed::UncheckedSigned
export interface V1SignedUncheckedSigned extends PolkadotPrimitivesV1SignedUncheckedSigned {}
// signed::UncheckedSigned
export interface SignedUncheckedSigned extends PolkadotPrimitivesV1SignedUncheckedSigned {}
// UncheckedSigned
export interface UncheckedSigned extends PolkadotPrimitivesV1SignedUncheckedSigned {} If there are conflicts on a short path, then don't apply an alias. It can actually always replace what is passed as input - since all tx, query, events, ... work of the metadata types. (Only RPC is problematic, but in that case e.g EDIT: Here is a PR that would extract short aliases (to be used in the typegen, not included above) - #4488 (Would need to be careful since it is a horribly slow & nested operation, so for now it is there but may not go in anytime soon-ish) |
What about namespacing?
Or something like that. The definitions may look messier but usage should look a bit cleaner |
No namespaces. |
Thanks for the write-up @monitz87
The manual types are optional afaik, I just followed this here https://polkadot.js.org/docs/api/start/typescript.user#chain-modules and ran successfully: yarn polkadot-types-from-chain --endpoint ws://localhost:9944 --output ./src/interfaces Now as pointed out in the issue, I also have red squiggles form anything imported from |
You need to add the |
Oh thanks I see, I missed this part. I ended up doing the following:
yarn polkadot-types-from-chain --endpoint ws://localhost:9944 --output ./src/interfaces
curl -H "Content-Type: application/json" -d '{"id":"1", "jsonrpc":"2.0", "method": "state_getMetadata", "params":[]}' http://localhost:9933 > ./custom-node-metadata.json
Now thanks to the paths in tsconfig, TS is happy. |
Hi, I am having a similar problem when trying to migrate to 7..x
|
This issue has been open for 21 days with no activity and is not labelled as an enhancement. It will be closed in 7 days. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query. |
Hi. I'm trying to migrate some typescript projects to use version 7.4.1 (from 5.1.1). The types are generated without issue, but the compiler throws a ton of errors when attempting to build the projects:
Module '"@polkadot/types/lookup"' has no exported member 'PalletImOnlineHeartbeat'
is a good example. None of the stuff being imported from@polkadot/types/lookup
can be foundCannot find name 'PolymeshPrimitivesDocument'
wherePolymeshPrimitivesDocument
is (I assume) some sort of wrapper over our customDocument
type. There is no indication that the augmented types are even trying to import the custom types from anywhereIs there some special configuration required in order to make this work in 7.x?
The text was updated successfully, but these errors were encountered: