I have set up a hardhat project with typescript a while ago and want to write some tests.
Now I only have a typechain-types
directory and it doesn't give me the types I am used to. Where is the plain typechain
directory? For instance this following code:
import { expect } from "chai";
import { ethers } from "hardhat";
import type {
Example
} from "../typechain-types";
async function doSomeExample() {
let example : Example
const signers = await ethers.getSigners()
const ExampleFactory = await ethers.getContractFactory('Example', signers[0])
example = await ExampleFactory.deploy()
}
gives me the Type-error: Type 'Contract' is missing the following properties from type 'Example': ...
in the pen-ultimate line.
I have - amongst others - installed the following packages in package.json
(it is a bit of a mess, admittedly):
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.5",
"@nomiclabs/hardhat-etherscan": "^3.0.3",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"@typechain/ethers-v5": "^10.1.0",
"@typechain/hardhat": "^6.0.0",
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.1",
"@types/node": "^17.0.31",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"ts-node": "^10.7.0",
"typechain": "^8.1.0",
"typescript": "^4.6.4",
...
},
"dependencies": {
"@typechain/truffle-v5": "^8.0.1",
"@typechain/web3-v1": "^6.0.1",
"hardhat-typechain": "^0.3.5",
"ts-generator": "^0.1.1",
...
}
My tsconfig.json
looks as follows:
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"outDir": "dist",
"declaration": true
},
"include": ["./scripts", "./test", "./typechain"],
"files": ["./hardhat.config.ts"]
}
and the hardhat.cofig.ts
starts with:
import { HardhatUserConfig, task } from "hardhat/config";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-waffle";
import "@typechain/hardhat";
...
Also cleaning the types and all that with npx hardhat clean
and re-compiling npx hardhat compile
won't generate the types at the correct directory with the expected behaviour. What am I doing wrong?