libp2p / js-libp2p

The JavaScript Implementation of libp2p networking stack.
https://libp2p.io
Other
2.27k stars 435 forks source link

libp2p.components not included in typescript types. #2452

Open MichaelJCole opened 4 months ago

MichaelJCole commented 4 months ago

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.

MichaelJCole commented 4 months ago

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