From 07c37656862584cb2b23138bbb48eb84753bcc26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Wed, 12 Jun 2024 14:51:14 +1200 Subject: [PATCH] fix: incorrect multi payload type --- apps/example/src/App.tsx | 3 +-- packages/core/src/QueryBuilder.ts | 36 +++++++++++++++---------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/apps/example/src/App.tsx b/apps/example/src/App.tsx index c6957193..a3ffad50 100644 --- a/apps/example/src/App.tsx +++ b/apps/example/src/App.tsx @@ -37,8 +37,7 @@ const Query = () => { .readStorage("Balances", "TotalIssuance", []) .readStorage("Staking", "ActiveEra", []) .readStorage("NominationPools", "TotalValueLocked", []) - .readStorages("NominationPools", "Metadata", [[0], [1], [2], [3], [4]]) - .readStorage("Treasury", "ProposalCount", []), + .readStorages("NominationPools", "Metadata", [[0], [1], [2], [3], [4]]), ); const bondingDurationMs = diff --git a/packages/core/src/QueryBuilder.ts b/packages/core/src/QueryBuilder.ts index d8bfdccd..e5505338 100644 --- a/packages/core/src/QueryBuilder.ts +++ b/packages/core/src/QueryBuilder.ts @@ -100,7 +100,7 @@ type ConstantFetchPayload< TypedApi["constants"][TInstruction["pallet"]][TInstruction["constant"]] >; -type StorageReadPayload< +type StorageReadResponse< TInstruction extends | StorageReadInstruction | MultiInstruction>, @@ -109,7 +109,7 @@ type StorageReadPayload< TypedApi["query"][TInstruction["pallet"]][TInstruction["storage"]] >["response"]; -type StorageEntriesReadPayload< +type StorageEntriesReadResponse< TInstruction extends StorageEntriesReadInstruction< any, any, @@ -121,7 +121,7 @@ type StorageEntriesReadPayload< TypedApi["query"][TInstruction["pallet"]][TInstruction["storage"]] >["response"]; -type ApiCallPayload< +type ApiCallResponse< TInstruction extends | ApiCallInstruction | MultiInstruction>, @@ -139,42 +139,42 @@ export type InferInstructionResponse< : TInstruction extends MultiInstruction< StorageReadInstruction > - ? Array> + ? Array> : TInstruction extends StorageReadInstruction - ? StorageReadPayload + ? StorageReadResponse : TInstruction extends StorageEntriesReadInstruction< any, any, any, TDescriptor > - ? StorageEntriesReadPayload + ? StorageEntriesReadResponse : TInstruction extends MultiInstruction< ApiCallInstruction > - ? Array> + ? Array> : TInstruction extends ApiCallInstruction< any, any, any, TDescriptor > - ? ApiCallPayload + ? ApiCallResponse : never; +type ResponsePayload = + T extends Promise + ? Payload + : T extends Observable + ? Payload + : T extends Array + ? Array> + : unknown; + export type InferInstructionPayload< TInstruction extends QueryInstruction, TDescriptor extends ChainDefinition = ReDotDescriptor, -> = - InferInstructionResponse extends Promise< - infer Payload - > - ? Payload - : InferInstructionResponse extends Observable< - infer Payload - > - ? Payload - : InferInstructionResponse; +> = ResponsePayload>; export type InferInstructionsResponse< TInstructions extends QueryInstruction[],