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

Problem with typings #4029

Closed
TrejGun opened this issue May 6, 2023 · 2 comments
Closed

Problem with typings #4029

TrejGun opened this issue May 6, 2023 · 2 comments
Assignees
Labels
fixed/complete This Bug is fixed or Enhancement is complete and published. investigate Under investigation and may be a bug. minor-bump Planned for the next minor version bump. v6 Issues regarding v6

Comments

@TrejGun
Copy link

TrejGun commented May 6, 2023

Ethers Version

6.3.0

Search Terms

No response

Describe the Problem

Hey there, it's time for me to migrate from v5 to v6 and I have some problems, can you please help me to solve them?!

1 log types are incompatible

import { Interface, JsonRpcProvider, Log, LogDescription } from "ethers";

const provider = new JsonRpcProvider();
const logs: Log[] = await provider.send("eth_getLogs", [
      {
        address,
        fromBlock,
        toBlock,
        topics,
      },
    ]);

const iface = new Interface(ERC721abi);

 for (const log of logs) {
      const description = iface.parseLog(log); // <-- ERROR
}
TS2345: Argument of type 'Log' is not assignable to parameter of type '{ topics: string[]; data: string; }'.   
Types of property 'topics' are incompatible.     
The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'string[]'.

I guess the reason is

parseLog(log: { topics: Array<string>, data: string}): null | LogDescription {

that has to be

parseLog(log: Log): null | LogDescription {
@nlordell
Copy link

nlordell commented Nov 7, 2023

I think you can just change the parseLog signature to:

parseLog(log: { topics: ReadonlyArray<string>, data: string }): null | LogDescription {
    // ...
}

One way to work around this is to augment the ethers modules typings with something like this:

// ethers.d.ts
import type { LogDescription } from 'ethers'

declare module 'ethers' {
  interface Interface {
    parseLog(log: { topics: ReadonlyArray<string>; data: string }): null | LogDescription
  }
}

@ricmoo ricmoo added on-deck This Enhancement or Bug is currently being worked on. minor-bump Planned for the next minor version bump. next-patch Issues scheduled for the next arch release. labels Jan 31, 2024
@ricmoo
Copy link
Member

ricmoo commented Feb 9, 2024

Fixed in v6.11.0.

Thanks! And let me know if you still have any issues. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed/complete This Bug is fixed or Enhancement is complete and published. investigate Under investigation and may be a bug. minor-bump Planned for the next minor version bump. v6 Issues regarding v6
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants