-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incompatible Typescript types between contracts #6419
Comments
Note: I'm not sure weither that is a Hardhat-viem issue (comming from how the ABI are extracted from artefacts) or a viem issue (comming from how contracts are typed). |
Hey @Amxx, is the repo you are working with open source, to help us reproduce the issue? |
Here is a minimal example: https://github.com/Amxx/hardhat3-minimal-example (just run |
Hi @Amxx , thanks for reporting the issue. I just wanted to share a quick update: we're still investigating it |
Hey @Amxx, as far as I can tell, this is a limitation from viem. Here's a minimal reproduction using only viem stuff: import { GetContractReturnType, WalletClient, parseAbi } from "viem";
const myContractAbi = parseAbi(["function executeMessage(string calldata) external payable returns (bytes4)"])
const myInterfaceAbi = parseAbi(["function executeMessage(string calldata input) external payable returns (bytes4)"])
type MyContract = GetContractReturnType<typeof myContractAbi, WalletClient>;
type MyInterface = GetContractReturnType<typeof myInterfaceAbi, WalletClient>;
let myContract: MyContract = null as any;
let myInterface: MyInterface = null as any;
myContract = myInterface
myInterface = myContract The last two lines won't compile because apparently using different names for a function produces incompatible ABI types. Adding a name other than "input" to I don't think there's much we can do on our side here, so I'll tentatively close this, but happy to take another look if there's anything with which we could help. |
Feedback
Disclaimer: I'm new to viem (comming from ethers.js), and that is my first type working with the viem typescript types.
I am trying to build functions that operate on "contracts object" that implement interfaces. I'm then calling these functions with "contract objects" that are actual implementation of the interfaces.
For example, lets consider the following solidity code
and the test code
Everything works fine, except I have a solidity warning
Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
So I decide to update my solidity code to
And that is when things start to break!
All of the sudden, I get a typescript error telling me that the types are incompatible. I guess that is because the ABI is not the same for the executeMessage function. In one case it has a named input, and in the other case it doesn't.
I'm getting errors about "legacy" and "eip7702" types being different. Not sure what tx envelops have to do with this, but it really isn't great.
In practice, compatible ABI are often implemented with minor changes to in args name. That doesn't break compatibility, and it should honestly no affect type resolution here.
The text was updated successfully, but these errors were encountered: