Skip to content

Commit

Permalink
feat: make AbiParameter['name'] optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Nov 9, 2022
1 parent 1ce41dc commit 94e2161
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-ducks-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'abitype': patch
---

Made `AbiParameter['name']` optional
2 changes: 1 addition & 1 deletion src/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export type AbiInternalType =

export type AbiParameter = {
type: ResolvedAbiType
name: string
name?: string
/** Representation used by Solidity compiler */
internalType?: AbiInternalType
} & (
Expand Down
14 changes: 10 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ export type AbiParameterToPrimitiveType<
]
: // All tuple parameters are named so return as object
{
[Component in TComponents[number] as Component['name']]: AbiParameterToPrimitiveType<Component>
[Component in TComponents[number] as Component extends {
name: string
}
? Component['name']
: never]: AbiParameterToPrimitiveType<Component>
}
: // 3. Check if type is array.
/**
Expand Down Expand Up @@ -144,9 +148,11 @@ type _HasUnnamedAbiParameter<TAbiParameters extends readonly AbiParameter[]> =
infer Head extends AbiParameter,
...infer Tail extends readonly AbiParameter[],
]
? Head['name'] extends ''
? true
: _HasUnnamedAbiParameter<Tail>
? Head extends { name: string }
? Head['name'] extends ''
? true
: _HasUnnamedAbiParameter<Tail>
: false
: false

/**
Expand Down

0 comments on commit 94e2161

Please sign in to comment.