Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Contract: no compilation error when accessing undefined properties & functions due to index signature #1138

Closed
rryter opened this issue Nov 6, 2020 · 5 comments
Labels
discussion Questions, feedback and general information.

Comments

@rryter
Copy link

rryter commented Nov 6, 2020

Hi there

Taken from issue dethcrypto/TypeChain#276 @zemse

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

    // The meta-class properties
    readonly [ key: string ]: ContractFunction | any;
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.

Would it be possible to fix this with a reasonable amount of effort?

@ricmoo
Copy link
Member

ricmoo commented Nov 6, 2020

You have no idea how many very long and late days I spent trying to get this "better" (less worse?).

I think the typing model for TypeScript 3.8 (which is what was out when I worked don that) was not quite ready. It might be now, I'll be looking into it again when I make the v6 changes to Contract. I also have some other ideas I may play with using templating.

But know this, I do not disagree with you; a tremendous amount of TypeScripts "umph" is lost as a result. :(

@ricmoo ricmoo added the discussion Questions, feedback and general information. label Nov 6, 2020
@rryter
Copy link
Author

rryter commented Nov 6, 2020

Appreciate the fast response. And I can relate a little bit I think :-) I too have spent hours and hours on typing related things. I'll look into it a bit next week, incase I learn anything useful, I will let you know. Thanks a lot!

@ricmoo
Copy link
Member

ricmoo commented Nov 6, 2020

Awesome! Yes, if you can figure anything meaningful out, let me know... I'm hoping new and interesting improvements will/have come out in TypeScript. :)

@rryter
Copy link
Author

rryter commented Nov 13, 2020

I'm afraid I did not come up with anything useful.

I think to "solve" the Typechain usecase, I just have to resort to the functions property. That way it will throw an error when the function does not exist.

@ricmoo
Copy link
Member

ricmoo commented Aug 24, 2021

For v6 I have some ideas that seem to be working thus far. :)

Moving to discussions though, in case anyone else wants to chime in...

@ethers-io ethers-io locked and limited conversation to collaborators Aug 24, 2021
@ricmoo ricmoo closed this as completed Aug 24, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
discussion Questions, feedback and general information.
Projects
None yet
Development

No branches or pull requests

2 participants