Contract: no compilation error when accessing undefined properties & functions due to index signature
See original GitHub issueHi 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 tomethodName2
, 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 originalContract
class.
Would it be possible to fix this with a reasonable amount of effort?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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!
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. 😦