js-libp2p
js-libp2p copied to clipboard
libp2p.components not included in typescript types.
-
Version: "libp2p": "^1.2.3",
-
Platform: Linux
-
Subsystem:
Severity:
High - The main functionality of the application does not work, API breakage, repo format breakage, etc.
Description:
Separating types into an interface creates a lot of extra work.
The point of typescript is to have the code, types, and documentation in the same place. The types are the documentation.
So the interface doesn't include components, but the implementation makes components public.
It's very difficult to contribute to this project because the code is spread all over the place.
It's not clear to me how to fix it in the interface package.
Components type can be exported from libp2p allowing for workarounds in the apps that use libp2p.
Steps to reproduce the error:
Try to get the results of what AutoNAT is doing.
To access the address manager, here is a workaround:
import { DefaultAddressManager } from 'libp2p/dist/src/address-manager'
// @ts-ignore broken libp2p types
const am = libp2p.components.addressManager as DefaultAddressManager
This is by design to simplify the public API and allow internal refactors without breaking that public API.
Typically internal components are only accessed by services, which are the way to extend the node with your own custom functionality which can be fully typed as expected.