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 to recognize api type annotations for different chain at one project #4969

Closed
cinlk opened this issue Jun 22, 2022 · 5 comments
Closed
Labels
Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance.

Comments

@cinlk
Copy link

cinlk commented Jun 22, 2022

We have two substrate chain with different metadata, and generate each of their const, query and tx api in same declare (same namespace) module. there are two same name storage method with different parameter type.
for example chainA has this storage method definition as follow:

balance:{
    storageVersion: AugmentedQuery<ApiType, () => Observable<**ChainAType**>, []> & QueryableStorageEntry<ApiType, []>;
}

chainB storage method definition as follow:

balance: {
      storageVersion: AugmentedQuery<ApiType, () => Observable<**ChainBType**>, []> & QueryableStorageEntry<ApiType, []>;

}

When I want to use both of their api in one project and set the tsconfig.json to apply 2 different api augmentations.

"paths": {
    "@polkadot/api-augment": [
      "./node_modules/@substrate/api-augment/chainA/index.d.ts",
     "./node_modules/@substrate/api-augment/chainB/index.d.ts"
     ],
} 

Initialing api with chainB provider find that the "api.qeury.balance.storageVersion" don't recognize chainB's type annotations, always use chainA's type annotations.

@jacogr
Copy link
Member

jacogr commented Jun 22, 2022

Due to the way TS augmentation works (see an article by DigitalOcean, another HOWTO or the official documentation, it would either -

  • apply the latest, i.e. latest in wins
  • may complain when there are parameter mismatches

This is not something solvable on the API layer. Augmentations in TS are alway additive.

@jacogr jacogr added the Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance. label Jun 22, 2022
@cinlk
Copy link
Author

cinlk commented Jun 22, 2022

well, Any idea to solve this problem? I think change TS declaration-merging rules is not a good way

@jacogr
Copy link
Member

jacogr commented Jun 22, 2022

There is no "solution", as mentioned above, not any changes that can be made not "not do this" - this is just how TS types are augmented, it tries to apply all and there is one winner.

@jacogr
Copy link
Member

jacogr commented Jul 6, 2022

Closing, works as expected with TS, non api-related.

@jacogr jacogr closed this as completed Jul 6, 2022
@polkadot-js-bot
Copy link

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.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Jul 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance.
Projects
None yet
Development

No branches or pull requests

3 participants