Skip to content

TypeScript Compilation issues with Mplex and Noise #1443

@dadepo

Description

@dadepo
  • Version:
{
  "name": "minimal",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "build": "rimraf ./build && tsc",
    "start": "npm run build && node build/index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^18.8.4",
    "rimraf": "^3.0.2",
    "typescript": "^4.8.4"
  },
  "dependencies": {
    "@chainsafe/libp2p-gossipsub": "4.1.1",
    "@chainsafe/libp2p-noise": "^9.0.0",
    "@libp2p/bootstrap": "^5.0.0",
    "@libp2p/mplex": "^7.0.0",
    "@libp2p/tcp": "^5.0.0",
    "@libp2p/floodsub": "^5.0.0",
    "libp2p": "^0.39.5"
  }
}

  • Platform:
21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:41 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T6000 arm64
  • Subsystem:

Severity:

Critical - System crash, application panic.

Description:

Creating a minimal typescript project based off the code in the example here, but unfortunately compiling does not work as it seems the type does not line up quite right. Is this a problem with the dependencies or the combination of the versions?

Steps to reproduce the error:

package.json is reproduced above

then inside the entry file I have:

import { createLibp2p } from 'libp2p'
import {tcp} from '@libp2p/tcp'
import {mplex} from '@libp2p/mplex'
import {Noise} from "@chainsafe/libp2p-noise";

const createNode = async () => {
        const node = await createLibp2p({
            addresses: {
                listen: ['/ip4/0.0.0.0/tcp/0']
            },
            transports: [tcp()()],
            streamMuxers: [mplex()()],
            connectionEncryption: [() => new Noise()],
        })

        await node.start()
        return node
    }

;(async () => {
    const topic = 'news'

    const [node1, node2] = await Promise.all([
        createNode(),
        createNode()
    ])

})()

Compiling fail with the following errors:

node_modules/libp2p/dist/src/connection-manager/index.d.ts:96:22 - error TS2420: Class 'DefaultConnectionManager' incorrectly implements interface 'ConnectionManager'.
  Property 'afterUpgradeInbound' is missing in type 'DefaultConnectionManager' but required in type 'ConnectionManager'.

96 export declare class DefaultConnectionManager extends EventEmitter<ConnectionManagerEvents> implements ConnectionManager, Startable, Initializable {
                        ~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/@libp2p/interface-connection-manager/dist/src/index.d.ts:33:5
    33     afterUpgradeInbound: () => void;
           ~~~~~~~~~~~~~~~~~~~
    'afterUpgradeInbound' is declared here.

src/index.ts:12:28 - error TS2322: Type 'StreamMuxerFactory' is not assignable to type 'RecursivePartial<StreamMuxerFactory>'.
  The types returned by 'createStreamMuxer(...).newStream(...)' are incompatible between these types.
    Type 'Stream | Promise<Stream>' is not assignable to type 'Stream'.
      Type 'Promise<Stream>' is missing the following properties from type 'Stream': close, closeRead, closeWrite, abort, and 6 more.

12             streamMuxers: [mplex()()],
                              ~~~~~~~~~

src/index.ts:13:36 - error TS2559: Type '() => Noise' has no properties in common with type 'RecursivePartial<ConnectionEncrypter>'.

13             connectionEncryption: [() => new Noise()],
                                      ~~~~~~~~~~~~~~~~~


Found 3 errors in 2 files.

Errors  Files
     1  node_modules/libp2p/dist/src/connection-manager/index.d.ts:96
     2  src/index.ts:12
error Command failed with exit code 2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    need/triageNeeds initial labeling and prioritization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions