Skip to content

args with keys helper? #225

Closed Answered by tmm
reslear asked this question in Q&A
Discussion options

You must be logged in to vote

You can do something like this:

TypeScript Playground

import {
  type AbiParameter,
  type AbiParameterKind,
  type AbiParameterToPrimitiveType,
} from 'abitype'

type AbiParametersToPrimitiveTypes<
  abiParameters extends readonly (AbiParameter & { name: string })[],
  abiParameterKind extends AbiParameterKind = AbiParameterKind,
> = {
  [name in abiParameters[number]['name']]: AbiParameterToPrimitiveType<
    Extract<abiParameters[number], { name: name }>,
    abiParameterKind
  >
}

type Result = AbiParametersToPrimitiveTypes<
  //   ^? type Result = { sender: `0x${string}`; recipient: `0x${string}`; amount: bigint; }
  [
    { name: 'sender'; type: 'address' },
    { name: 'recipient'; 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by reslear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants