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

Allow arbitrary property access on event arguments #698

Closed

Conversation

HenryNguyen5
Copy link

@HenryNguyen5 HenryNguyen5 commented Jan 6, 2020

The current typing for Event['args'] does not allow for us to use the added properties, since typescript will error out and say that the property does not exist on the type of Array.

For example, let's say that we have the event with the arguments foo and bar.

const tx = await myContractInstance.myMethod()

// gives us an event of { 0: '0xDEAD', 1: '0xBEEF', foo: '0xDEAD', bar: '0xBEEF' }
const receipt = await tx.wait()

// works
receipt.events.args[0] // 0xDEAD

// does not work, property does not exist on type Array<any>
receipt.events.args.foo // 0xDEAD

This PR fixes that, so that we can access arbitrary properties on our args arrayish-object.

@ricmoo
Copy link
Member

ricmoo commented Jan 6, 2020

I like this idea! I tried doing something like this before, but had no idea how to syntax it... I may pull this up and use it in a more generic sense. Let me look into it. :)

@HenryNguyen5
Copy link
Author

Sweet, let me know if you have any syntax questions for making it more generic, happy to help

@ricmoo ricmoo added enhancement New feature or improvement. next version labels Jan 8, 2020
@ricmoo
Copy link
Member

ricmoo commented Jan 8, 2020

I've added this in 5.0.0-beta.164. Try it out and let me know if I pulled it in correctly. :)

I moved this up to the AbiCoder level and return it from the .decode method.

@ricmoo ricmoo added the fixed/complete This Bug is fixed or Enhancement is complete and published. label Jan 8, 2020
@HenryNguyen5
Copy link
Author

Would you be able to backport this to 4.x? We haven't used 5.x yet since its not marked as stable

@ricmoo
Copy link
Member

ricmoo commented Mar 13, 2020

I'm a little apprehensive about changing this in v4 with TS 2.9. The last seemingly innocent change to the types broke a bunch of people, which I'd like to avoid. I agree this should be backwards compatible, but v5 is so close, I'd rather hold off... Make sense?

@HenryNguyen5
Copy link
Author

Sounds good to me @ricmoo

@ricmoo
Copy link
Member

ricmoo commented Mar 14, 2020

Awesome! I'll close this PR then (it has been merged into v5).

Thanks! :)

@ricmoo ricmoo closed this Mar 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants