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

Enable TS errors when ethers v5 contract object does not have a method #276

Closed
zemse opened this issue Aug 29, 2020 · 2 comments
Closed

Comments

@zemse
Copy link
Contributor

zemse commented Aug 29, 2020

This line in the Contract class is pulling back the power of typescript.

const rainbowInstance = RainbowFactory.connect(address, provider);
rainbowInstance.methodThatDoesntExist(); // any

If solidity method methodName is renamed to methodName2, there should be typescript errors in the typescript project to be able to fix it. But ATM, it doesn't error in this case due to the wild card in the original Contract class.

Is there any way to disable/override this wildcard? It'd enable errors before runtime in projects! I think it can be a great addition to ethers v5 target (as well as help me to smoothly introduce breaking changes in my current project's test-net contracts in test-cases as well as UIs).

@krzkaczor
Copy link
Member

This is definitely a problem. I tried to tackle it in the past but finally gave up.

I see two solutions:

  1. Try to use type-level-programming (Omit) to drop [ key: string ]: ContractFunction | any; It's possible to fix subtypes with wildcards using this approach (like functions) but I didn't have any luck fixing top-level wildcard.

  2. Simply copy the whole Contract type and manually delete the wildcard. This approach can result in over-reliance on implementation details of ethersjs and break often in the future.

CC: @ricmoo Maybe ethers could expose BaseContract type without any wildcards?

@krzkaczor
Copy link
Member

This works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants