question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Misleading types for `EnsProvider.getResolver()`

See original GitHub issue

The getResolver() method on the EnsProvider interface is declared with the following signature

export interface EnsProvider {
    getResolver(name: string): Promise<EnsResolver | null>;
}

The implementation of getResolver() can return null though https://github.com/ethers-io/ethers.js/blob/4e9394554b1f05400ea4e0529d33e1d4efe78247/packages/providers/src.ts/base-provider.ts#L1515-L1524

This leads to callers of getResolver() not anticipating null as the return value which leads to runtime errors even though type-checking passes. I’d expect the following signature.

export interface EnsProvider {
    getResolver(name: string): Promise<EnsResolver | null>;
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ricmoocommented, Oct 4, 2021

I’m adding this locally for the next minor bump now. 😃

Keep in mind a large portion of the library will still have the same problem if you are. “anticipating” things to not be null. The library is overall designed around the strict error in the TypeScript checker turned off, so anything can return null.

This is changed in v6 (which uses strict errors), and has required a lot of little changes, and v6 is still not ready for a public beta yet. But for the most part in v5, these sorts of changes will not be made anymore…

0reactions
ricmoocommented, Oct 20, 2021

The types have been updated in 5.5.0.

Thanks! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

ethersproject/providers - UNPKG
1, "use strict";. 2. 3, import {. 4, Block, BlockTag, BlockWithTransactions, EventType, Filter, FilterByBlockHash, ForkEvent,. 5, Listener, Log, Provider, ...
Read more >
EIP-5131: SAFE Authentication For ENS
Abstract. This EIP links one or more signing wallets via Ethereum Name Service Specification (EIP-137) to prove control and asset ownership ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found