Type 'BaseContract & Omit<ContractInterface, keyof BaseContract>' is missing the following properties

740 views Asked by At

I'm using @nomicfoundation/hardhat-toolbox v3.0.0 that uses ethers v6.

The below code works in ethers v5 with @nomicfoundation/hardhat-toolbox v2.0.2

import { FundMe } from "./../../typechain-types"

describe("FundMe", async () => {
    let fundMe: FundMe

    beforeEach(async () => {

        const fundMeContract = await deployments.get("FundMe")

        fundMe = (await ethers.getContractAt(
            fundMeContract.abi,
            fundMeContract.address
        )) as FundMe
    })
})

With the new version, I'm getting the following error:

Conversion of type 'Contract' to type 'FundMe' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Type 'BaseContract & Omit<ContractInterface, keyof BaseContract>' is missing the following properties from type 'FundMe': attach, deployed, functions, MINIMUM_USD, and 9 more.

I've tried:

fundMe = await ethers.getContractAt( fundMeContract.abi, fundMeContract.address )

And getting the error:

Expected 0 type arguments, but got 1.ts(2558)

OR

fundMe = await ethers.getContractAt(
            fundMeContract.abi,
            fundMeContract.address
        )

And I get the error:

Type 'BaseContract & Omit<ContractInterface, keyof BaseContract>' is missing the following properties from type 'FundMe': attach, deployed, functions, MINIMUM_USD, and 9 more

What can I do to make it work with Typescript despite using the any type ?
The code works but VSCode is showing the error. enter image description here

2

There are 2 answers

0
MentatX On

Same problem. I'm using the workaround for now:

...
fundMe = (await (ethers as any).getContractAt(
...
0
chaosrei On

Try to include typechain-types directory into "tsconfig.json".

Here's a sample "tsconfig.json":

{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true,
    "outDir": "dist",
    "resolveJsonModule": true
  },
  "include": ["./scripts", "./test", "./typechain-types"],
  "files": ["./hardhat.config.ts"]
}