diff --git a/src/connection/connection.d.ts b/src/connection/connection.d.ts index 41c289f..ff6f014 100644 --- a/src/connection/connection.d.ts +++ b/src/connection/connection.d.ts @@ -30,8 +30,8 @@ declare class Connection { * @param {string} [properties.stat.encryption] connection encryption method identifier. */ constructor({ localAddr, remoteAddr, localPeer, remotePeer, newStream, close, getStreams, stat }: { - localAddr: multiaddr; - remoteAddr: multiaddr; + localAddr: multiaddr | undefined; + remoteAddr: multiaddr | undefined; localPeer: PeerId; remotePeer: PeerId; newStream: Function; @@ -43,8 +43,8 @@ declare class Connection { open: string; upgraded: string; }; - multiplexer: string; - encryption: string; + multiplexer: string | undefined; + encryption: string | undefined; }; }); /** @@ -54,11 +54,11 @@ declare class Connection { /** * Observed multiaddr of the local peer */ - localAddr: multiaddr; + localAddr: multiaddr | undefined; /** * Observed multiaddr of the remote peer */ - remoteAddr: multiaddr; + remoteAddr: multiaddr | undefined; /** * Local peer id. */ @@ -77,8 +77,8 @@ declare class Connection { open: string; upgraded: string; }; - multiplexer?: string; - encryption?: string; + multiplexer?: string | undefined; + encryption?: string | undefined; }; /** * Reference to the new stream function of the multiplexer @@ -113,8 +113,8 @@ declare class Connection { open: string; upgraded: string; }; - multiplexer?: string; - encryption?: string; + multiplexer?: string | undefined; + encryption?: string | undefined; }; /** * Get all the streams of the muxer. diff --git a/src/pubsub/index.d.ts b/src/pubsub/index.d.ts index a327bf7..cbb6881 100644 --- a/src/pubsub/index.d.ts +++ b/src/pubsub/index.d.ts @@ -34,9 +34,9 @@ declare class PubsubBaseProtocol { globalSignaturePolicy: { StrictSign: "StrictSign"; StrictNoSign: string; - }; - canRelayMessage: boolean; - emitSelf: boolean; + } | undefined; + canRelayMessage: boolean | undefined; + emitSelf: boolean | undefined; }); log: any; /** @@ -285,13 +285,13 @@ declare namespace PubsubBaseProtocol { } type PeerId = import("peer-id"); type InMessage = { - from?: string; + from?: string | undefined; receivedFrom: string; topicIDs: string[]; - seqno?: Uint8Array; + seqno?: Uint8Array | undefined; data: Uint8Array; - signature?: Uint8Array; - key?: Uint8Array; + signature?: Uint8Array | undefined; + key?: Uint8Array | undefined; }; import PeerStreams = require("./peer-streams"); /** diff --git a/src/pubsub/utils.d.ts b/src/pubsub/utils.d.ts index 1cc14a4..c400623 100644 --- a/src/pubsub/utils.d.ts +++ b/src/pubsub/utils.d.ts @@ -3,11 +3,11 @@ export function msgId(from: string, seqno: Uint8Array): Uint8Array; export function noSignMsgId(data: Uint8Array): Uint8Array; export function anyMatch(a: Set | any[], b: Set | any[]): boolean; export function ensureArray(maybeArray: T | T[]): T[]; -export function normalizeInRpcMessage(message: T, peerId?: string): T & { - from?: string; - peerId?: string; +export function normalizeInRpcMessage(message: T, peerId?: string | undefined): T & { + from?: string | undefined; + peerId?: string | undefined; }; -export function normalizeOutRpcMessage(message: T): T & { - from?: Uint8Array; - data?: Uint8Array; +export function normalizeOutRpcMessage(message: T): T & { + from?: Uint8Array | undefined; + data?: Uint8Array | undefined; }; diff --git a/src/topology/index.d.ts b/src/topology/index.d.ts index 70241f4..83bc5c9 100644 --- a/src/topology/index.d.ts +++ b/src/topology/index.d.ts @@ -17,12 +17,12 @@ declare class Topology { * @constructor */ constructor({ min, max, handlers }: { - min: number; - max: number; + min: number | undefined; + max: number | undefined; handlers: { - onConnect: Function; - onDisconnect: Function; - }; + onConnect?: Function | undefined; + onDisconnect?: Function | undefined; + } | undefined; }); min: number; max: number; diff --git a/src/topology/multicodec-topology.d.ts b/src/topology/multicodec-topology.d.ts index 06d16f5..343e3f1 100644 --- a/src/topology/multicodec-topology.d.ts +++ b/src/topology/multicodec-topology.d.ts @@ -18,8 +18,8 @@ declare class MulticodecTopology extends Topology { * @constructor */ constructor({ min, max, multicodecs, handlers }: { - min: number; - max: number; + min: number | undefined; + max: number | undefined; multicodecs: Array; handlers: { onConnect: Function; @@ -34,7 +34,7 @@ declare class MulticodecTopology extends Topology { * @param {Array} props.protocols */ _onProtocolChange({ peerId, protocols }: { - peerId: any; + peerId: PeerId; protocols: Array; }): void; /** @@ -42,18 +42,22 @@ declare class MulticodecTopology extends Topology { * @param {Connection} connection * @returns {void} */ - _onPeerConnect(connection: any): void; + _onPeerConnect(connection: Connection): void; /** * Update topology. * @param {Array<{id: PeerId, multiaddrs: Array, protocols: Array}>} peerDataIterable * @returns {void} */ _updatePeers(peerDataIterable: Array<{ - id: any; - multiaddrs: Array; + id: PeerId; + multiaddrs: Array; protocols: Array; }>): void; - get [multicodecTopologySymbol](): boolean; +} +declare namespace MulticodecTopology { + export { PeerId, Multiaddr, Connection }; } import Topology = require("."); -declare const multicodecTopologySymbol: unique symbol; +type PeerId = import("peer-id"); +type Connection = typeof import("../connection"); +type Multiaddr = import("multiaddr"); diff --git a/tsconfig.json b/tsconfig.json index 482bfe8..2902998 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ // Tells TypeScript to read JS files, as // normally they are ignored as source files "allowJs": true, + "strict": true, // Generate d.ts files "declaration": true, // This compiler run should