diff --git a/packages/web3-eth-abi/src/types.ts b/packages/web3-eth-abi/src/types.ts index 926fdc66402..fc6014ed78e 100644 --- a/packages/web3-eth-abi/src/types.ts +++ b/packages/web3-eth-abi/src/types.ts @@ -186,14 +186,21 @@ export type MatchPrimitiveType< | never; export type ContractMethodOutputParameters | undefined> = + // check if params are empty array Params extends readonly [] - ? [] - : Params extends readonly [infer H, ...infer R] + ? void // if yes outputs is void + : Params extends readonly [infer H, ...infer R] // check if Params is array ? H extends AbiParameter - ? // TODO: Find a way to set name for tuple item - [MatchPrimitiveType, ...ContractMethodOutputParameters] + ? [ + MatchPrimitiveType, + ...ContractMethodOutputParameters, + ] & + H['name'] extends '' // check if output param name is empty string + ? [] + : Record> & // sets key-value pair of output param name and type + ContractMethodOutputParameters : ContractMethodOutputParameters - : Params extends undefined | unknown + : Params extends undefined | unknown // param is not array, check if undefined ? [] : Params;