Skip to content

fix: update deployContract to use generics for constructor args with arrays#224

Open
jose-blockchain wants to merge 3 commits into1inch:masterfrom
jose-blockchain:fix/deployContract-type-error-208
Open

fix: update deployContract to use generics for constructor args with arrays#224
jose-blockchain wants to merge 3 commits into1inch:masterfrom
jose-blockchain:fix/deployContract-type-error-208

Conversation

@jose-blockchain
Copy link

@jose-blockchain jose-blockchain commented Jan 20, 2026

Description

Fixes type mismatch error when passing arrays (e.g., readonly [100, 500, 3000, 10000]) as constructor parameters to deployContract.

The previous type Array<BigNumberish> was too restrictive and didn't match ContractFactory.deploy(...args: ContractMethodArgs<A>) when arrays were included in constructor parameters.

Changes

  • Updated deployContract function to use generics with Abi type parameter (Solution B)
  • Changed parameters type from Array<BigNumberish> to readonly any[] to allow arrays and complex types
  • Added helper types DeployContractParameters and DeployContractReturn for better type safety
  • Function now accepts arrays like readonly [100, 500, 3000, 10000] as constructor parameters

Testing

  • Existing tests continue to pass (backward compatible)
  • Function signature properly typed with generics
  • No linter errors

Related Issues

Fixes #208
Potenrial reviewers: @mayar-deeb-xi @k06a @ZumZoom

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Fixes type mismatch when passing arrays (e.g., readonly number[]) to deployContract constructor parameters.
Implemented Solution B using generics with Abi type parameter to align with ContractFactory.deploy types.

The function now accepts arrays and complex types in constructor parameters, resolving the issue where Array<BigNumberish> didn't match ContractFactory.deploy(...args: ContractMethodArgs<A>).

Related Issues: 1inch#208
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the deployContract helper in src/utils.ts to address a TypeScript type mismatch when passing array/tuple-like constructor arguments (e.g., readonly [100, 500, 3000, 10000]) to ContractFactory.deploy.

Changes:

  • Added Abi-generic deployContract signature intended to better align with ethers factory deployment argument typing.
  • Relaxed constructor-parameter typing to allow arrays/complex types by accepting a readonly any[].
  • Introduced helper types for deploy parameters/return types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

jose-blockchain and others added 2 commits March 5, 2026 07:18
removing `ContractFactory` import, unused

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jose-blockchain
Copy link
Author

please review, this is an external collab.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

src/utils.ts Outdated
export async function deployContract<abi extends Abi = Abi>(
name: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
parameters: DeployContractParameters<abi> = [] as any
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value parameters = [] as any is likely unnecessary because [] is already assignable to the annotated type (readonly any[]). Dropping the cast reduces any usage without changing the function’s flexibility.

Suggested change
parameters: DeployContractParameters<abi> = [] as any
parameters: DeployContractParameters<abi> = []

Copilot uses AI. Check for mistakes.
Comment on lines +275 to +276
export async function deployContract<abi extends Abi = Abi>(
name: string,
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generic type parameter name abi is lowercase, which makes it easy to confuse with a runtime value and is inconsistent with other generics in this file (e.g., T). Consider renaming it to something like TAbi/TContractAbi for clarity.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

type error: deployContract from utils.ts

2 participants