Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Utilize generic to better support Typechain types #1475

Closed
wants to merge 1 commit into from

Conversation

phated
Copy link

@phated phated commented Apr 15, 2021

I'm guessing this will need to be iterated a bit, but I wanted to open this for discussion.

Essentially, what we are hoping to achieve is a better devex than using as Something to cast a contract to a Typechain contract type, which already extends ether's Contract.

The result would look something like this:

const UtilsFactory = await hre.ethers.getContractFactory('Utils');

// Notice the `: UtilsContract ` here, which casts the Contract return to the Typechain type
const utils: UtilsContract = await UtilsFactory.deploy();

await utils.deployed();

// We could then use custom RPC methods on UtilsContract and have it fully typechecked here.

@ricmoo
Copy link
Member

ricmoo commented Apr 16, 2021

I think TypeChain has already added this, by extending the BaseContract object, no?

The abstraction has been added to ethers, to make it easier for this sort of abstraction, check out #1384 and let me know if that helps.

@phated
Copy link
Author

phated commented Apr 16, 2021

@ricmoo Thanks for pointing me to those changes. I tried upgrading everything in my lockfile and I think there's still a problem because when I get the following typechecking error:

Type 'Contract' is missing the following properties from type 'UtilsContract': testFn, "testFn(bytes32[])", changeAdmin, "changeAdmin(address)", and 18 more.ts(2740)

cc @krzkaczor

@ricmoo ricmoo added the discussion Questions, feedback and general information. label Apr 16, 2021
@krzkaczor
Copy link

I reopened that issue as I run into some problems (see #1384 (comment)).

@phated regarding this issue. This is not really related to ethers but to Hardhat and TypeChain integration. You will love this: dethcrypto/TypeChain#370

Btw. thanks for CCing me in this thread ;)

@phated
Copy link
Author

phated commented Jun 6, 2021

I think this is solved by typechain v5

@phated phated closed this Jun 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Questions, feedback and general information.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants