TypeChain icon indicating copy to clipboard operation
TypeChain copied to clipboard

Event argument name conflicts with JS method values()

Open vpavlin opened this issue 3 years ago • 3 comments

Hi all,

I've just noticed that Openzeppelin's IGovernor.sol interface defines an event with argumetn values (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/governance/IGovernor.sol#L28-L37)

When I try to use the generated typings, I get that event.args.values is undefined - I believe this is because of the clash between the argument name and the JS object method values()

Is there a way to check for reserved keywords and pre/su-fix the name values with an underscore or something like that?

I can access it by index as well, but it would be messy to mix accesing content by . and []. It might be also an issue for other reserved words.

vpavlin avatar Feb 17 '22 11:02 vpavlin

I've experimented with this a bit, and we could strip keys conflicting with Array prototype methods from the event type, and you'd still have to use event.args[3] or destructuring. event.args.values is the array method at runtime.

const [proposalId, proposer, targets, values, signatures, calldatas, startBlock, endBlock, description] = event.args;

To prefix or postfix .values, we'd have to introduce more runtime code and overlap with the responsibilities of ethers.js or web3.

@krzkaczor what do you think about this?

hasparus avatar Mar 17 '22 15:03 hasparus

Thanks for looking into it!

vpavlin avatar Mar 17 '22 15:03 vpavlin

as @hasparus noted: https://github.com/dethcrypto/TypeChain/pull/654#issuecomment-1072313143, we are thinking that this is low priority issue without a clean solution. For now, we suggest renaming clashing symbols manually in the ABI (ex. values => _values).

If more ppl want us to prioritize it, please speak up.

krzkaczor avatar Mar 18 '22 13:03 krzkaczor