typescript - Type 'BaseContract & Omit' mangler følgende egenskaper


Jeg bruker @nomicfoundation/hardhat-toolbox v3.0.0 som bruker ethers v6.

Koden under fungerer i ethers v5 med @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
    })
})

Med den nye versjonen får jeg følgende feil:

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.

Jeg har prøvd:

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

Og får feilen:

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

ELLER

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

Og jeg får feilen:

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

Hva kan jeg gjøre for å få det til å fungere med Typescript til tross for at jeg bruker typen any?
Koden fungerer, men VSCode viser feilen.

Svar #1

Prøv å inkludere typechain-types-mappen i "tsconfig.json".

Her er et eksempel på "tsconfig.json":

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

Svar #2

Samme problem. Jeg bruker midlertidig løsningen for nå:

...
fundMe = (await (ethers as any).getContractAt(
...