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

Incorrect Typing on contract.queryFilter #2882

Closed
rzmay opened this issue Apr 7, 2022 · 3 comments
Closed

Incorrect Typing on contract.queryFilter #2882

rzmay opened this issue Apr 7, 2022 · 3 comments
Assignees
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published. minor-bump Planned for the next minor version bump.

Comments

@rzmay
Copy link

rzmay commented Apr 7, 2022

Ethers Version

5.6.2

Search Terms

No response

Describe the Problem

There's an incorrect type definition on the queryFilter method of the BaseContract class. The event argument's type on line 1041 is only used once in the method, on the call to this._getRunningEvent on the immediately following line.

private _getRunningEvent(eventName: EventFilter | string): RunningEvent {
        // ...
}

queryFilter(event: EventFilter, fromBlockOrBlockhash?: BlockTag | string, toBlock?: BlockTag): Promise<Array<Event>> {
        const runningEvent = this._getRunningEvent(event);
        // ...
}

The type for the argument passed to this._getRunningEvent is EventFilter | string, but the only allowed type for the event argument in the queryFilter method is EventFilter. The type of the event argument on the queryFilter method should match the type in the _getRunningEvent.

Suggested change:

queryFilter(event: EventFilter | string, fromBlockOrBlockhash?: BlockTag | string, toBlock?: BlockTag): Promise<Array<Event>> { /* ... */ }

Code Snippet

// Type '"MyEventName"' has no properties in common with type 'EventFilter'.
const events = await contract.queryFilter('MyEventName', block);

Contract ABI

No response

Errors

No response

Environment

No response

Environment (Other)

No response

@rzmay rzmay added the investigate Under investigation and may be a bug. label Apr 7, 2022
@henriqueoelze
Copy link

Facing the same problem here and agreed with everything above.

@ricmoo
Copy link
Member

ricmoo commented Apr 12, 2022

The call only narrows the type, but I agree, it seems like a wasted opportunity. This will require a minor version bump, and I'll tag it for that, but I don't plan one in next few weeks at least, unless there is a strong need for one.

In the meantime though, this should work:

const logs = await contract.queryFilter(contract.filters.Transfer());

You could also cast it to an EventFilter, but that feels uncomfy...

In v6, things are much more flexible as you can pass in "Transfer", contract.filters.Transfer or contract.filters.Transfer() to all achieve the same thing.

@ricmoo ricmoo added minor-bump Planned for the next minor version bump. enhancement New feature or improvement. and removed investigate Under investigation and may be a bug. labels Apr 12, 2022
@ricmoo ricmoo added on-deck This Enhancement or Bug is currently being worked on. fixed/complete This Bug is fixed or Enhancement is complete and published. labels Aug 14, 2022
@ricmoo ricmoo removed the on-deck This Enhancement or Bug is currently being worked on. label Aug 19, 2022
@ricmoo
Copy link
Member

ricmoo commented Aug 19, 2022

This has been updated in v5.7.0.

Thanks! :)

@ricmoo ricmoo closed this as completed Aug 19, 2022
Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this issue Jan 14, 2024
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. minor-bump Planned for the next minor version bump.
Projects
None yet
Development

No branches or pull requests

3 participants