-
Notifications
You must be signed in to change notification settings - Fork 853
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
Experimental web3js: RPC methods with no inputs are typed unknown
#1389
Comments
Shit. This is ringing some {I filed this bug with TypeScript} bells that I hoped never to hear again. |
That looks like the one and doesn't seem to have a fix A hacky workaround that would probably work would be adding an optional empty config object to these functions. Easy for a caller to ignore when they write the call (and for us to document in typedocs), and then should just work like everything else from there. Think that's worth doing? |
Yes please! Add it and liberally You can make the config object |
This fixes an issue where TS incorrectly types their returns as `unknown` See solana-labs#1389
This provider makes 3 requests, and makes their responses available to child components: - `getFirstAvailableBlock` - `getEpochInfo` - `getEpochSchedule` The first 2 are reasonably straightforward, we have basically the same structure as the legacy web3js, with just number/bigint changes. `getEpochSchedule` is a bit more complex. The existing API exposes a class with a bunch of functionality for finding the epoch for a slot, and the first/last slot for an epoch. None of this is RPC functionality, it's all baked into the legacy web3js code. Since the experimental web3js doesn't do any of that, I've copied these functions into the Explorer codebase, as pure functions that take an `EpochSchedule` (pure data returned by the new RPC method) and a slot/epoch (bigint). See existing web3js code here: https://github.com/solana-labs/solana-web3.js/blob/9232d2b1019dc50f852ad70aa81624e751d76161/packages/library-legacy/src/epoch-schedule.ts Also note that I hit a bug in experimental web3js where some of these functions are incorrectly typed as unknown: solana-labs/solana-web3.js#1389 This was easy enough to work around for now I've also moved `localStorageIsAvailable` from `utils/index.ts` to its own `utils/local-storage`. This lets us import it without pulling in the web3js dependency in `utils/index.ts` The result of this PR is that the `ClusterProvider` in the root layout no longer pulls in the legacy web3js dependency.
…ds with no params This fixes an issue where TS incorrectly types their returns as `unknown` See solana-labs#1389
…ds with no params This fixes an issue where TS incorrectly types their returns as `unknown` See solana-labs#1389
Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up. |
Overview
I'm trying to use
getFirstAvailableBlock
,getEpochInfo
andgetEpochSchedule
in a refactor of Explorer. I've found that the return ofgetFirstAvailableBlock
andgetEpochSchedule
are typed asunknown
by TypeScript. HowevergetEpochInfo
is typed correctly even when called with no parameters, I think because it has an optional parameter.Steps to reproduce
See replit: https://replit.com/@mcintyre94/web3js-unknown#index.ts
See how TypeScript types these incorrectly:
We also see this in the autocomplete:
I've also seen this locally using VSCode so it's not a Replit issue
Description of bug
As far as I can tell this only happens with RPC methods that take no inputs, either optional or required
I'm guessing we need to tighten up the proxy a bit to correctly type this case
The full message when autocompleting
getEpochSchedule
is:The text was updated successfully, but these errors were encountered: