不久前,我已经建立了一个带有类型记录的草帽项目,并想编写一些测试。现在我只有一个typechain-types目录,它没有给出我习惯的类型。普通的typechain目录在哪里?例如,以下代码:
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()
}给我类型错误:Type 'Contract' is missing the following properties from type 'Example': ...在钢笔-最终行.
除其他外,我在package.json中安装了以下软件包(无可否认,这有点混乱):
"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",
...
}我的tsconfig.json看起来如下:
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"outDir": "dist",
"declaration": true
},
"include": ["./scripts", "./test", "./typechain"],
"files": ["./hardhat.config.ts"]
}hardhat.cofig.ts的开头是:
import { HardhatUserConfig, task } from "hardhat/config";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-waffle";
import "@typechain/hardhat";
...同样,使用npx hardhat clean和重新编译npx hardhat compile来清理类型和所有这些类型都不会按照预期的行为在正确的目录中生成这些类型。我做错了什么?
发布于 2022-12-06 10:00:26
可以在hardhat配置文件中定义typechain输出目标。
若要接收所需的“平原”类型目录,请将以下内容添加到您的配置文件中:
const config: HardhatUserConfig = {
solidity: {
...
},
typechain: {
outDir: "typechain",
target: "ethers-v5",
},
networks: {
...
},
}发布于 2022-08-03 10:47:13
尝试重新初始化您的“硬帽子”项目并使用默认的类型记录模板。
如果有用的话,请投票给我:)
https://ethereum.stackexchange.com/questions/130907
复制相似问题