Web3.js: Web3 constructor does not accept custom/non-standard providers in TypeScript

Created on 19 Feb 2020  路  2Comments  路  Source: ChainSafe/web3.js

Overview

Related to https://github.com/ethereum/web3.js/issues/2266

There should be a way to overload the TypeScript definition of Web3 constructor to accept custom providers. I've tried everything, even declaration merging won't work. The easiest solution I foresee, which would not be a breaking change, is to provide a basic Provider interface which all providers must implement. Using a generic type parameter would be even more ideal, because it means properties like currentProvider could be strongly typed, even if they are custom/non-standard.

Right now the only workaround is to cast the provider to any, which is not ideal.

Steps to reproduce the behavior

  1. Set up TS project
  2. Attempt to construct Web3 instance with non-standard provider
1.x good first issue types

Most helpful comment

@nivida @smithki I am picking it up. Will update once I am done :)

All 2 comments

@nivida @smithki I am picking it up. Will update once I am done :)

This issue hasn't been updated in a month, so I created #3451

Was this page helpful?
0 / 5 - 0 ratings