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

Type 'Web3EthereumProvider' is not assignable to type 'AsyncSendable' in web3.js >= 1.0.0-beta.38 #490

Closed
bohendo opened this issue Apr 16, 2019 · 4 comments

Comments

@bohendo
Copy link

bohendo commented Apr 16, 2019

I'm trying to follow the web3 integration cookbook receipt in Typescript:

this.provider = new eth.providers.Web3Provider(opts.web3.currentProvider)

Where opts.web3 is an instance of a more recent web3.js release > 1.0.0-beta.37

I get an error while transpiling:

src/Wallet.ts:34:54 - error TS2345: Argument of type 'Web3EthereumProvider | HttpProvider | IpcProvider | WebsocketProvider | CustomProvider' is not assignable to parameter of type 'AsyncSendable'.
  Type 'Web3EthereumProvider' is not assignable to type 'AsyncSendable'.
    Types of property 'send' are incompatible.
      Type '(method: string, parameters: any[]) => Promise<any>' is not assignable to type '(request: any, callback: (error: any, response: any) => void) => void'.
        Types of parameters 'parameters' and 'callback' are incompatible.
          Type '(error: any, response: any) => void' is missing the following properties from type 'any[]': pop, push, concat, join, and 25 more.

34       this.provider = new eth.providers.Web3Provider(opts.web3.currentProvider)
                                                        ~~~~~~~~~~~~~~~~~~~~~~~~~

Looks like web3.js HttpProvider got up upgraded interface in versions >= 1.0.0-beta.38:

export class HttpProvider {
    constructor(host: string, options?: HttpProviderOptions);
    host: string;
    connected: boolean;
    send(method: string, parameters: any[]): Promise<object>;
    sendBatch(methods: AbstractMethod[], moduleInstance: AbstractWeb3Module): Promise<object[]>;
    disconnect(): boolean;
}

And ethers.providers.Web3Provider is expecting an AsyncSendable w an interface:

export type AsyncSendable = {
    isMetaMask?: boolean;
    host?: string;
    path?: string;
    sendAsync?: (request: any, callback: (error: any, response: any) => void) => void
    send?: (request: any, callback: (error: any, response: any) => void) => void
}

Looks like web3's new interface is specced out in EPI-1193 and issue #235 mentioned this.

Using ethers version ^4.0.27

@bohendo
Copy link
Author

bohendo commented Apr 16, 2019

Oops, right after submitting I found #374, looks like this is a dup

@bohendo bohendo closed this as completed Apr 16, 2019
@bohendo
Copy link
Author

bohendo commented Apr 16, 2019

Oops, #374 is related but this isn't actually a dup

@bohendo bohendo reopened this Apr 16, 2019
@ricmoo
Copy link
Member

ricmoo commented Apr 16, 2019

Does it work if you cast it to any?

It is hard to deal with all the signature changes in a backward compatible way... But I can likely just expand the definition.

@bohendo
Copy link
Author

bohendo commented Apr 16, 2019

Cool, compilation errors disappear with:

this.provider = new eth.providers.Web3Provider((opts.web3.currentProvider as any))

I'll reopen if I encounter related issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants