Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit 3143efd

Browse files
committed
fix: tsconfig to generate optionals correctly
1 parent f2d6a76 commit 3143efd

File tree

6 files changed

+41
-36
lines changed

6 files changed

+41
-36
lines changed

src/connection/connection.d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ declare class Connection {
3030
* @param {string} [properties.stat.encryption] connection encryption method identifier.
3131
*/
3232
constructor({ localAddr, remoteAddr, localPeer, remotePeer, newStream, close, getStreams, stat }: {
33-
localAddr: multiaddr;
34-
remoteAddr: multiaddr;
33+
localAddr: multiaddr | undefined;
34+
remoteAddr: multiaddr | undefined;
3535
localPeer: PeerId;
3636
remotePeer: PeerId;
3737
newStream: Function;
@@ -43,8 +43,8 @@ declare class Connection {
4343
open: string;
4444
upgraded: string;
4545
};
46-
multiplexer: string;
47-
encryption: string;
46+
multiplexer: string | undefined;
47+
encryption: string | undefined;
4848
};
4949
});
5050
/**
@@ -54,11 +54,11 @@ declare class Connection {
5454
/**
5555
* Observed multiaddr of the local peer
5656
*/
57-
localAddr: multiaddr;
57+
localAddr: multiaddr | undefined;
5858
/**
5959
* Observed multiaddr of the remote peer
6060
*/
61-
remoteAddr: multiaddr;
61+
remoteAddr: multiaddr | undefined;
6262
/**
6363
* Local peer id.
6464
*/
@@ -77,8 +77,8 @@ declare class Connection {
7777
open: string;
7878
upgraded: string;
7979
};
80-
multiplexer?: string;
81-
encryption?: string;
80+
multiplexer?: string | undefined;
81+
encryption?: string | undefined;
8282
};
8383
/**
8484
* Reference to the new stream function of the multiplexer
@@ -113,8 +113,8 @@ declare class Connection {
113113
open: string;
114114
upgraded: string;
115115
};
116-
multiplexer?: string;
117-
encryption?: string;
116+
multiplexer?: string | undefined;
117+
encryption?: string | undefined;
118118
};
119119
/**
120120
* Get all the streams of the muxer.

src/pubsub/index.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ declare class PubsubBaseProtocol {
3434
globalSignaturePolicy: {
3535
StrictSign: "StrictSign";
3636
StrictNoSign: string;
37-
};
38-
canRelayMessage: boolean;
39-
emitSelf: boolean;
37+
} | undefined;
38+
canRelayMessage: boolean | undefined;
39+
emitSelf: boolean | undefined;
4040
});
4141
log: any;
4242
/**
@@ -285,13 +285,13 @@ declare namespace PubsubBaseProtocol {
285285
}
286286
type PeerId = import("peer-id");
287287
type InMessage = {
288-
from?: string;
288+
from?: string | undefined;
289289
receivedFrom: string;
290290
topicIDs: string[];
291-
seqno?: Uint8Array;
291+
seqno?: Uint8Array | undefined;
292292
data: Uint8Array;
293-
signature?: Uint8Array;
294-
key?: Uint8Array;
293+
signature?: Uint8Array | undefined;
294+
key?: Uint8Array | undefined;
295295
};
296296
import PeerStreams = require("./peer-streams");
297297
/**

src/pubsub/utils.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ export function msgId(from: string, seqno: Uint8Array): Uint8Array;
33
export function noSignMsgId(data: Uint8Array): Uint8Array;
44
export function anyMatch(a: Set<any> | any[], b: Set<any> | any[]): boolean;
55
export function ensureArray<T>(maybeArray: T | T[]): T[];
6-
export function normalizeInRpcMessage<T extends unknown>(message: T, peerId?: string): T & {
7-
from?: string;
8-
peerId?: string;
6+
export function normalizeInRpcMessage<T extends Object>(message: T, peerId?: string | undefined): T & {
7+
from?: string | undefined;
8+
peerId?: string | undefined;
99
};
10-
export function normalizeOutRpcMessage<T extends unknown>(message: T): T & {
11-
from?: Uint8Array;
12-
data?: Uint8Array;
10+
export function normalizeOutRpcMessage<T extends Object>(message: T): T & {
11+
from?: Uint8Array | undefined;
12+
data?: Uint8Array | undefined;
1313
};

src/topology/index.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ declare class Topology {
1717
* @constructor
1818
*/
1919
constructor({ min, max, handlers }: {
20-
min: number;
21-
max: number;
20+
min: number | undefined;
21+
max: number | undefined;
2222
handlers: {
23-
onConnect: Function;
24-
onDisconnect: Function;
25-
};
23+
onConnect?: Function | undefined;
24+
onDisconnect?: Function | undefined;
25+
} | undefined;
2626
});
2727
min: number;
2828
max: number;

src/topology/multicodec-topology.d.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ declare class MulticodecTopology extends Topology {
1818
* @constructor
1919
*/
2020
constructor({ min, max, multicodecs, handlers }: {
21-
min: number;
22-
max: number;
21+
min: number | undefined;
22+
max: number | undefined;
2323
multicodecs: Array<string>;
2424
handlers: {
2525
onConnect: Function;
@@ -34,26 +34,30 @@ declare class MulticodecTopology extends Topology {
3434
* @param {Array<string>} props.protocols
3535
*/
3636
_onProtocolChange({ peerId, protocols }: {
37-
peerId: any;
37+
peerId: PeerId;
3838
protocols: Array<string>;
3939
}): void;
4040
/**
4141
* Verify if a new connected peer has a topology multicodec and call _onConnect.
4242
* @param {Connection} connection
4343
* @returns {void}
4444
*/
45-
_onPeerConnect(connection: any): void;
45+
_onPeerConnect(connection: Connection): void;
4646
/**
4747
* Update topology.
4848
* @param {Array<{id: PeerId, multiaddrs: Array<Multiaddr>, protocols: Array<string>}>} peerDataIterable
4949
* @returns {void}
5050
*/
5151
_updatePeers(peerDataIterable: Array<{
52-
id: any;
53-
multiaddrs: Array<any>;
52+
id: PeerId;
53+
multiaddrs: Array<Multiaddr>;
5454
protocols: Array<string>;
5555
}>): void;
56-
get [multicodecTopologySymbol](): boolean;
56+
}
57+
declare namespace MulticodecTopology {
58+
export { PeerId, Multiaddr, Connection };
5759
}
5860
import Topology = require(".");
59-
declare const multicodecTopologySymbol: unique symbol;
61+
type PeerId = import("peer-id");
62+
type Connection = typeof import("../connection");
63+
type Multiaddr = import("multiaddr");

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Tells TypeScript to read JS files, as
77
// normally they are ignored as source files
88
"allowJs": true,
9+
"strict": true,
910
// Generate d.ts files
1011
"declaration": true,
1112
// This compiler run should

0 commit comments

Comments
 (0)