hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

Temperature check: More robust type integration

Open flux627 opened this issue 4 years ago • 2 comments

I am looking to help implement a feature, and am creating this issue to see if the changes would be welcome by maintainers.

Right now, contract type information when using Typescript and TypeChain relies heavily on casting, and while is usually "good enough", it's still surface area for human error (especially when copy-pasting boilerplate). It would also just "be nice" if it "just worked". I propose a few things that would help close this gap:

  • ~Make Artifact optionally generic, allowing you to pass in the Contract and ContractFactory types~
  • Enumerate all contracts when generating TypeChain types, adding overloads to artifacts.readArtifact to return typed Artifact objects using the above generic
  • ~Change signature of Waffle's deployContract to be aware of the passed in Artifact's Contract and ContractFactory types, returning the correct Contract type and also validating constructor args~
  • ~Enumerate all contracts when generating TypeChain types, adding overloads to ethers' getContractFactory and getContractAt to return typed contract factory and contract instances (respectively)~

(see comment below for updated plan)

None of these changes would be breaking changes for existing TypeScript/TypeChain users (or any other users).

I already have most of this working by editing the source files directly, and I would just have to organize the changes into PRs across the various repositories. Let me know if this approach seems reasonable, and also if I forgot anything that would be complementary in this effort.

flux627 avatar Jul 24 '21 16:07 flux627