Closed CyclopsRex closed 1 year ago
Unfortunately the unlink
was done due to a limitation of typechain, see : https://github.com/dethcrypto/TypeChain/issues/399
There might be other way around for now though and welcome PR to solve it.
Getting same problem. For me, seems to be related to npm install --save-dev @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers
from installation instructions results in typechain typed contract data. If I install both hardhat-ethers and hardhat-deploy-ethers as separate packages (without the alias(?)) typing works but I no longer have access to ethers.getContract().
Might be worth voicing your issue in https://github.com/dethcrypto/TypeChain/issues/399 too
typechain is currently hard-coding the type from @nomiclabs/hardhat-ethers and this what make it incompatible with hardhat-deploy-ethers that add extra types to hre.ethers
Will do. Thanks for the tip.
workaround
workaround
Thanks for the suggestion. I tried adding to my deployment but it had no effect (I.e. no typechain definitions for my solidity contracts).
So is the idea here that type definitions for ethers deploy getContract, etc are pulled from the hardhat deploy types rather than from the typechain-types dir?
For someone that found this issue, a current workaround to keep the types is to pass the typechain type to the generic of the getContract
function. But is more verbose than the native approach from typechain
Get the type from the typechain folder
pass to getContract
@edumudu thanks. This worked for me. But, yes, you're correct, it adds verbosity to the code.
@edumudu thanks. This worked for me. But, yes, you're correct, it adds verbosity to the code.
Further to my implementation of importing and declaring typechain types explicitly, I've found that this only works if I have the typechain types already generated (i.e. ./typechain-types dir already exists), otherwise I get a "cannot find module typechain-types". As typechain even recommends NOT committing the typechain-types dir to source control, Therefore, I cannot generate typechain-types because it is looking for typechain-types during compilation, hence I'm stuck in a failure loop.
Edit: Whoops. Seems like you can ignore missing imports with // @ts-ignore
// @ts-ignore
import type { ArbitrageMediator } from "../typechain-types";
Latest version 0.4.1 allow you to specify a generic
Background
I have a typescript codebase which deploys some contracts and then calls functions on them according to their specific type. e.g.
In this example,
myContract
is given typeMtyContract
. This is exactly what I want, and without fully understanding all the code it seems to be facilitated by atypechain/hardhat.d.ts
file, which was generated when I ranhh typechain
.So far, so good.
Issue
After installing
hardhat-deploy
by runningnpm install -D hardhat-deploy
andnpm install --save-dev @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers
, I find thathardhat.d.ts
has gone missing andmyContract
now has the much less useful type ofContract
. I can explicitly cast it but this code appears in a hundred places in it's a pain to do so, as well as unnecessarily verbose.This seems to be related to the
unlink
introduced in f4b68f729b96982b8497cd538c46fd8dbd0eed97, which removes thehardhat.d.ts
file that contains the properly typed functions, immediately after it is generated.There is also a similar problem with
attach
, though I'm not sure that has the same root cause cos this seems to come from somewhere other thanhardhat.d.ts
?Question
Hardhat-deploy seems nice but is there a way to have it play nicely and maintain all the strongly typed contracts I've become used to, both when calling
deploy
on a factory and when callingattach
?It's perfectly possible that I've just missed an instruction or mistyped something, but after debugging for quite a while only to find the
unlink
, I'm at a bit of loss.Extract from package.json follows: