Skip to content

Commit

Permalink
fix: encodeDeployData type should accept no constructor (#2374)
Browse files Browse the repository at this point in the history
* fix: encodeDeployData type should accept no constructor

* changeset

* Update itchy-frogs-doubt.md

---------

Co-authored-by: William Cory <williamcory@Williams-MacBook-Pro.local>
Co-authored-by: jxom <jakemoxey@gmail.com>
  • Loading branch information
3 people authored Jun 11, 2024
1 parent 3856da6 commit a81965e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-frogs-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Updated `EncodeDeployDataParameters` type.
20 changes: 18 additions & 2 deletions src/utils/abi/encodeDeployData.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,25 @@ test('no const assertion', () => {
})
})

test('abi has no constructor', () => {
// @ts-expect-error abi has no constructor
test('abi has no constructor and no args', () => {
encodeDeployData({
bytecode: '0x420',
abi: [
{
inputs: [],
name: 'Foo',
outputs: [],
type: 'error',
},
],
})
})

test('abi has no constructor and includes args', () => {
encodeDeployData({
bytecode: '0x420',
// @ts-expect-error
args: [123n],
abi: [
{
inputs: [],
Expand Down
11 changes: 6 additions & 5 deletions src/utils/abi/encodeDeployData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ export type EncodeDeployDataParameters<
abi: abi
bytecode: Hex
} & UnionEvaluate<
readonly [] extends allArgs
? { args?: allArgs | undefined }
: { args: allArgs }
> &
(hasConstructor extends true ? unknown : never)
hasConstructor extends false
? { args?: undefined }
: readonly [] extends allArgs
? { args?: allArgs | undefined }
: { args: allArgs }
>

export type EncodeDeployDataReturnType = Hex

Expand Down

0 comments on commit a81965e

Please sign in to comment.