dethcrypto / TypeChain

🔌 TypeScript bindings for Ethereum smart contracts
MIT License
2.76k stars 365 forks source link

getting wrong type after .connect() #856

Open gameblock1 opened 1 year ago

gameblock1 commented 1 year ago

Hi I am unable to use .connect() as it changes the type to what it has already generated regardless of the type I determined.

import { ethers } from "hardhat";
import {Lock, Lock2} from "../typechain-types"

type Lock1AndLock2 = Lock2 & Lock

describe("Sample", function() {
    it("Should have the same type", async function() {
        const Lock = (await ethers.getContractAt(abi, address)) as unknown as Lock1AndLock2; // type: Lock1AndLock2
        const LockWithDifferentRunner = Lock.connect(undefined); // type: Lock2

        /*
          Currently:
            Lock: Lock1AndLock2
            LockWithDifferentRunner: Lock2
        */

        /*
          Expected:
            Lock: Lock1AndLock2
            LockWithDifferentRunner: Lock1AndLock2

            why the type of LockWithDifferentRunner changed after conencting to a different runenr?
        */
    })
})
zemse commented 1 year ago

This requires this type in return of https://github.com/dethcrypto/TypeChain/blob/ec6b8600042e78020af3e05647e5044bd44425b9/packages/target-ethers-v6/src/codegen/index.ts#L69