question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Hi there

Taken from issue https://github.com/ethereum-ts/TypeChain/issues/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?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rrytercommented, 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!

1reaction
ricmoocommented, 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. 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I prevent the error "Index signature of object type ...
We can access all object property names during compilation phase by keyof keyword (see changelog). You only need to replace string variable type...
Read more >
Index Signatures in TypeScript - Dmitri Pavlutin
Property 'baseSalary' is incompatible with index signature. Type 'string' is not assignable to type 'number'.2345Argument of type '{ baseSalary: ...
Read more >
20 TypeScript Flags You Should be Using | Academy
In this article, I'll show you 20 TypeScript compiler options that my team and I use and recommend to our clients. Then, we'll...
Read more >
TypeScript errors and how to fix them
error TS1337 : An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead....
Read more >
A simple guide to “interface” data type in TypeScript - Medium
If you want an object to basically have any property, then you can explicitly mark a value any and the TypeScript compiler won't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found