PatrickAlphaC / hardhat-smartcontract-lottery-fcc

MIT License
117 stars 183 forks source link

Property 'args' does not exist on type 'EventLog | Log'. Property 'args' does not exist on type 'Log'.ts(2339) any #198

Closed milosdjurica closed 7 months ago

milosdjurica commented 7 months ago

Property 'args' does not exist on type 'EventLog | Log'. Property 'args' does not exist on type 'Log'.ts(2339) any

In this specific test ->

it("emits the event", async () => {
                    await lottery.enterLottery({ value: TICKET_PRICE });
                    await network.provider.send("evm_increaseTime", [
                        Number(INTERVAL) + 1,
                    ]);
                    await network.provider.send("evm_mine", []);
                    const txResponse = await lottery.performUpkeep("0x");
                    const txReceipt = await txResponse.wait(1);
                    const requestId = txReceipt?.logs[1].args.requestId;
                    // console.log("requestId", requestId);
                    assert(Number(requestId) > 0);
                });

there is this weird TypeScript error for this line of code ->

txReceipt?.logs[1].args.requestId;

Code still works, but the compiler will screams on you if you don't parse it as EventLog type. The solution for this would be ->

(txReceipt?.logs[1] as EventLog).args.requestId;

I solved error by myself, but had to do a lot of digging in order to find solution. Hopefully this help someone in the future and saves their time. :)