polkadot-api / polkadot-api

Polkadot-API is a meticulously crafted suite of libraries, each designed to be composable, modular, and aligned with a "light-client first" philosophy
https://papi.how
MIT License
97 stars 24 forks source link

unioned descriptors doesn't compile in batch call #637

Closed ryanleecode closed 2 months ago

ryanleecode commented 2 months ago
  1. clone https://github.com/ryanleecode/papi-test-3
  2. pnpm i
  3. npx tsc --noEmit

number 3 doesnt compile but 2 and 1 does. the checksums are also the same on both sides.

josepot commented 2 months ago

Why would this be a bug? Please elaborate better, because this looks to me as someone purposely shooting themselves in the foot.

ryanleecode commented 2 months ago

Why would it not be a bug? It doesnt compile

ryanleecode commented 2 months ago

you have a typed union of two descriptors polkadot people and westend people both sides have the same checksum yet it doesnt compile as a union but when passed the same parameters without a union it compiles.

this is a perfectly legitimate usecase

josepot commented 2 months ago

Open a discussion if you if you wish, and whenever I have time I will explain how you can use TS effectively to achieve this.

In the meanwhile, please do know that when you do things like this:

  const network: keyof typeof descriptorMap = "westend2" as keyof typeof descriptorMap;
  const peopleApi = client.getTypedApi(descriptorMap[network]);

then, as you can imagine, the calls that don't have enough type overlap, like utility.batch won't work, not even with an empty array. Therefore, if you really want to do that kind of stuff (which most of the times you shouldn't), then you have to pick one of the APIs. For instance, you could do:

(peopleApi as TypedApi<typeof descriptorMap['westend2']>).tx.Utility.batch({ calls });