首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在我的“硬帽子”项目中创建类型目录?

如何在我的“硬帽子”项目中创建类型目录?
EN

Ethereum用户
提问于 2022-06-29 00:54:06
回答 2查看 1.2K关注 0票数 1

不久前,我已经建立了一个带有类型记录的草帽项目,并想编写一些测试。现在我只有一个typechain-types目录,它没有给出我习惯的类型。普通的typechain目录在哪里?例如,以下代码:

代码语言:javascript
复制
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中安装了以下软件包(无可否认,这有点混乱):

代码语言:javascript
复制
"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看起来如下:

代码语言:javascript
复制
{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true,
    "outDir": "dist",
    "declaration": true
  },
  "include": ["./scripts", "./test", "./typechain"],
  "files": ["./hardhat.config.ts"]
}

hardhat.cofig.ts的开头是:

代码语言:javascript
复制
import { HardhatUserConfig, task } from "hardhat/config";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-waffle";
import "@typechain/hardhat";

...

同样,使用npx hardhat clean和重新编译npx hardhat compile来清理类型和所有这些类型都不会按照预期的行为在正确的目录中生成这些类型。我做错了什么?

EN

回答 2

Ethereum用户

回答已采纳

发布于 2022-12-06 10:00:26

可以在hardhat配置文件中定义typechain输出目标。

若要接收所需的“平原”类型目录,请将以下内容添加到您的配置文件中:

代码语言:javascript
复制
const config: HardhatUserConfig = {
solidity: {
    ...
  },
  typechain: {
    outDir: "typechain",
    target: "ethers-v5",
  },
  networks: {
    ...
  },
}
票数 1
EN

Ethereum用户

发布于 2022-08-03 10:47:13

尝试重新初始化您的“硬帽子”项目并使用默认的类型记录模板。

如果有用的话,请投票给我:)

票数 2
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/130907

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档