Closed rin-st closed 2 months ago
Tysm @rin-st, yeah it was bug indeed!
Maybe a good solution would be :
By doing this we make sure the type of eventName
is locked to one eventName in generic (checkout next section for more details) and will get the right autocompletion and won't get errors.
Diagnostics: 1. Property 'newGreeting' does not exist on type '(readonly [string, string, boolean, bigint] | readonly [string, bigint]) & ({ greetingSetter?: string | undefined; newGreeting?: string | undefined; premium?: boolean | undefined; value?: bigint | undefined; } | { ...; })'. Property 'newGreeting' does not exist on type 'readonly [string, string, boolean, bigint] & { someString?: string | undefined; someValue?: bigint | undefined; }'. [2339]
As I understand from the error, due to multiple events there were multiple possibilities of event names ("GreetingChange | "SomeOtherEvent") and because of that multiple possibilities of args and since newGreeting
is not present in SomeOtherEvent
TS is throwing error (since it's not present in all possible args, TS gets it resultant type as common things checkout this minimal example)
The reason for TS getting multiple possibilities was because while passing eventName
as arg to useScaffoldWatchEvent
, the generic TEventName
was not assigned to eventName
in type, because of which the second generic slot of useScaffoldWatchEvent
was not getting locked to literal string (eventName
passed) instead it was remaining union of "GreetingChange" | "SomeOtherEvent"
always. Checkout below examples :
Also not at all related to this PR (please feel free to ignore), but it seems wagmi's useWatchContractEvent
does not give autocompletion for eventName
checkout this example, am I doing something wrong?
Thanks Shiv! Great solution!
The reason for TS getting multiple possibilities was because while passing eventName as arg to useScaffoldWatchEvent, the generic TEventName was not assigned to eventName in type, because of which the second generic slot of useScaffoldWatchEvent was not getting locked to literal string (eventName passed) instead it was remaining union of "GreetingChange" | "SomeOtherEvent" always.
Yes, I assigned TEventName to eventName too. And for me autocomplete also works. But your solution looks better, so changed to your variant.
One question, how did you understand that eventName
is somewhere inside UseWatchContractEventParameters
? Because of eventName
in generic parameters? I didn't even search it 🤷♂️
Also not at all related to this PR (please feel free to ignore), but it seems wagmi's useWatchContractEvent does not give autocompletion for eventName checkout this example, am I doing something wrong?
Doesn't work for me too
and also on JS land wagmi's useWatchContractEvent was accepting it as a param
🤦 sure, thanks!
Description
Currently, types of arguments doesn't work as expected when contract has more that one event. Example:
if I just add
event SomeOtherEvent(string someString, uint256 someValue);
toYourContract.sol
, I'm receiving this error when trying to work with logs fromuseScaffoldWatchContractEvent
.Additional Information