fix: tsconfig to generate optionals correctly

This commit is contained in:
Irakli Gozalishvili 2020-11-30 16:55:33 -08:00
parent f2d6a76dcf
commit 3143efd7c1
No known key found for this signature in database
GPG Key ID: C80F9B292FB470DE
6 changed files with 41 additions and 36 deletions

View File

@ -30,8 +30,8 @@ declare class Connection {
* @param {string} [properties.stat.encryption] connection encryption method identifier. * @param {string} [properties.stat.encryption] connection encryption method identifier.
*/ */
constructor({ localAddr, remoteAddr, localPeer, remotePeer, newStream, close, getStreams, stat }: { constructor({ localAddr, remoteAddr, localPeer, remotePeer, newStream, close, getStreams, stat }: {
localAddr: multiaddr; localAddr: multiaddr | undefined;
remoteAddr: multiaddr; remoteAddr: multiaddr | undefined;
localPeer: PeerId; localPeer: PeerId;
remotePeer: PeerId; remotePeer: PeerId;
newStream: Function; newStream: Function;
@ -43,8 +43,8 @@ declare class Connection {
open: string; open: string;
upgraded: string; upgraded: string;
}; };
multiplexer: string; multiplexer: string | undefined;
encryption: string; encryption: string | undefined;
}; };
}); });
/** /**
@ -54,11 +54,11 @@ declare class Connection {
/** /**
* Observed multiaddr of the local peer * Observed multiaddr of the local peer
*/ */
localAddr: multiaddr; localAddr: multiaddr | undefined;
/** /**
* Observed multiaddr of the remote peer * Observed multiaddr of the remote peer
*/ */
remoteAddr: multiaddr; remoteAddr: multiaddr | undefined;
/** /**
* Local peer id. * Local peer id.
*/ */
@ -77,8 +77,8 @@ declare class Connection {
open: string; open: string;
upgraded: string; upgraded: string;
}; };
multiplexer?: string; multiplexer?: string | undefined;
encryption?: string; encryption?: string | undefined;
}; };
/** /**
* Reference to the new stream function of the multiplexer * Reference to the new stream function of the multiplexer
@ -113,8 +113,8 @@ declare class Connection {
open: string; open: string;
upgraded: string; upgraded: string;
}; };
multiplexer?: string; multiplexer?: string | undefined;
encryption?: string; encryption?: string | undefined;
}; };
/** /**
* Get all the streams of the muxer. * Get all the streams of the muxer.

14
src/pubsub/index.d.ts vendored
View File

@ -34,9 +34,9 @@ declare class PubsubBaseProtocol {
globalSignaturePolicy: { globalSignaturePolicy: {
StrictSign: "StrictSign"; StrictSign: "StrictSign";
StrictNoSign: string; StrictNoSign: string;
}; } | undefined;
canRelayMessage: boolean; canRelayMessage: boolean | undefined;
emitSelf: boolean; emitSelf: boolean | undefined;
}); });
log: any; log: any;
/** /**
@ -285,13 +285,13 @@ declare namespace PubsubBaseProtocol {
} }
type PeerId = import("peer-id"); type PeerId = import("peer-id");
type InMessage = { type InMessage = {
from?: string; from?: string | undefined;
receivedFrom: string; receivedFrom: string;
topicIDs: string[]; topicIDs: string[];
seqno?: Uint8Array; seqno?: Uint8Array | undefined;
data: Uint8Array; data: Uint8Array;
signature?: Uint8Array; signature?: Uint8Array | undefined;
key?: Uint8Array; key?: Uint8Array | undefined;
}; };
import PeerStreams = require("./peer-streams"); import PeerStreams = require("./peer-streams");
/** /**

12
src/pubsub/utils.d.ts vendored
View File

@ -3,11 +3,11 @@ export function msgId(from: string, seqno: Uint8Array): Uint8Array;
export function noSignMsgId(data: Uint8Array): Uint8Array; export function noSignMsgId(data: Uint8Array): Uint8Array;
export function anyMatch(a: Set<any> | any[], b: Set<any> | any[]): boolean; export function anyMatch(a: Set<any> | any[], b: Set<any> | any[]): boolean;
export function ensureArray<T>(maybeArray: T | T[]): T[]; export function ensureArray<T>(maybeArray: T | T[]): T[];
export function normalizeInRpcMessage<T extends unknown>(message: T, peerId?: string): T & { export function normalizeInRpcMessage<T extends Object>(message: T, peerId?: string | undefined): T & {
from?: string; from?: string | undefined;
peerId?: string; peerId?: string | undefined;
}; };
export function normalizeOutRpcMessage<T extends unknown>(message: T): T & { export function normalizeOutRpcMessage<T extends Object>(message: T): T & {
from?: Uint8Array; from?: Uint8Array | undefined;
data?: Uint8Array; data?: Uint8Array | undefined;
}; };

View File

@ -17,12 +17,12 @@ declare class Topology {
* @constructor * @constructor
*/ */
constructor({ min, max, handlers }: { constructor({ min, max, handlers }: {
min: number; min: number | undefined;
max: number; max: number | undefined;
handlers: { handlers: {
onConnect: Function; onConnect?: Function | undefined;
onDisconnect: Function; onDisconnect?: Function | undefined;
}; } | undefined;
}); });
min: number; min: number;
max: number; max: number;

View File

@ -18,8 +18,8 @@ declare class MulticodecTopology extends Topology {
* @constructor * @constructor
*/ */
constructor({ min, max, multicodecs, handlers }: { constructor({ min, max, multicodecs, handlers }: {
min: number; min: number | undefined;
max: number; max: number | undefined;
multicodecs: Array<string>; multicodecs: Array<string>;
handlers: { handlers: {
onConnect: Function; onConnect: Function;
@ -34,7 +34,7 @@ declare class MulticodecTopology extends Topology {
* @param {Array<string>} props.protocols * @param {Array<string>} props.protocols
*/ */
_onProtocolChange({ peerId, protocols }: { _onProtocolChange({ peerId, protocols }: {
peerId: any; peerId: PeerId;
protocols: Array<string>; protocols: Array<string>;
}): void; }): void;
/** /**
@ -42,18 +42,22 @@ declare class MulticodecTopology extends Topology {
* @param {Connection} connection * @param {Connection} connection
* @returns {void} * @returns {void}
*/ */
_onPeerConnect(connection: any): void; _onPeerConnect(connection: Connection): void;
/** /**
* Update topology. * Update topology.
* @param {Array<{id: PeerId, multiaddrs: Array<Multiaddr>, protocols: Array<string>}>} peerDataIterable * @param {Array<{id: PeerId, multiaddrs: Array<Multiaddr>, protocols: Array<string>}>} peerDataIterable
* @returns {void} * @returns {void}
*/ */
_updatePeers(peerDataIterable: Array<{ _updatePeers(peerDataIterable: Array<{
id: any; id: PeerId;
multiaddrs: Array<any>; multiaddrs: Array<Multiaddr>;
protocols: Array<string>; protocols: Array<string>;
}>): void; }>): void;
get [multicodecTopologySymbol](): boolean; }
declare namespace MulticodecTopology {
export { PeerId, Multiaddr, Connection };
} }
import Topology = require("."); import Topology = require(".");
declare const multicodecTopologySymbol: unique symbol; type PeerId = import("peer-id");
type Connection = typeof import("../connection");
type Multiaddr = import("multiaddr");

View File

@ -6,6 +6,7 @@
// Tells TypeScript to read JS files, as // Tells TypeScript to read JS files, as
// normally they are ignored as source files // normally they are ignored as source files
"allowJs": true, "allowJs": true,
"strict": true,
// Generate d.ts files // Generate d.ts files
"declaration": true, "declaration": true,
// This compiler run should // This compiler run should