How is the type definition for custom contract supported? #3566
-
Given the following code:
I wonder how typescript definition is enabled for the contract name with literal "Simple". |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
This is done by typechain's Hardhat plugin which creates a file overriding the type definition of |
Beta Was this translation helpful? Give feedback.
-
Hi @alcuadrado , Given the following code.
The issue I am facing is that, there is no type support on This is more of a typescript question instead of hardhat question though. |
Beta Was this translation helpful? Give feedback.
-
I don't think there's a way to type that automatically in typescript. Take a look at how typechain works in the sample project:
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
import { ethers } from "ethers";
import {
FactoryOptions,
HardhatEthersHelpers as HardhatEthersHelpersBase,
} from "@nomiclabs/hardhat-ethers/types";
import * as Contracts from ".";
declare module "hardhat/types/runtime" {
interface HardhatEthersHelpers extends HardhatEthersHelpersBase {
getContractFactory(
name: "Lock",
signerOrOptions?: ethers.Signer | FactoryOptions
): Promise<Contracts.Lock__factory>;
getContractAt(
name: "Lock",
address: string,
signer?: ethers.Signer
): Promise<Contracts.Lock>;
// default types
getContractFactory(
name: string,
signerOrOptions?: ethers.Signer | FactoryOptions
): Promise<ethers.ContractFactory>;
getContractFactory(
abi: any[],
bytecode: ethers.utils.BytesLike,
signer?: ethers.Signer
): Promise<ethers.ContractFactory>;
getContractAt(
nameOrAbi: string | any[],
address: string,
signer?: ethers.Signer
): Promise<ethers.Contract>;
}
} It explicitly defines every overload. |
Beta Was this translation helpful? Give feedback.
I don't think there's a way to type that automatically in typescript.
Take a look at how typechain works in the sample project:
typechain-types/hardhat.d.ts
: