fix: add type annotations to improve innference

This commit is contained in:
Irakli Gozalishvili 2020-11-30 13:59:09 -08:00
parent cba63941b0
commit 4e25c6e51c
No known key found for this signature in database
GPG Key ID: C80F9B292FB470DE
3 changed files with 17 additions and 12 deletions

View File

@ -1,7 +1,7 @@
'use strict' 'use strict'
module.exports = { module.exports = {
OPEN: 'open', OPEN: /** @type {'open'} */('open'),
CLOSING: 'closing', CLOSING: /** @type {'closing'} */('closing'),
CLOSED: 'closed' CLOSED: /** @type {'closed'} */('closed')
} }

View File

@ -13,7 +13,7 @@ exports.SignaturePolicy = {
* * Enforce the fields to be present, reject otherwise. * * Enforce the fields to be present, reject otherwise.
* * Propagate only if the fields are valid and signature can be verified, reject otherwise. * * Propagate only if the fields are valid and signature can be verified, reject otherwise.
*/ */
StrictSign: 'StrictSign', StrictSign: /** @type {'StrictSign'} */ ('StrictSign'),
/** /**
* On the producing side: * On the producing side:
* * Build messages without the signature, key, from and seqno fields. * * Build messages without the signature, key, from and seqno fields.
@ -24,5 +24,5 @@ exports.SignaturePolicy = {
* * Propagate only if the fields are absent, reject otherwise. * * Propagate only if the fields are absent, reject otherwise.
* * A message_id function will not be able to use the above fields, and should instead rely on the data field. A commonplace strategy is to calculate a hash. * * A message_id function will not be able to use the above fields, and should instead rely on the data field. A commonplace strategy is to calculate a hash.
*/ */
StrictNoSign: 'StrictNoSign' StrictNoSign: /** @type {'StrictNoSign'} */ 'StrictNoSign'
} }

View File

@ -71,8 +71,9 @@ exports.anyMatch = (a, b) => {
/** /**
* Make everything an array. * Make everything an array.
* *
* @param {any} maybeArray * @template T
* @returns {Array} * @param {T|T[]} maybeArray
* @returns {T[]}
* @private * @private
*/ */
exports.ensureArray = (maybeArray) => { exports.ensureArray = (maybeArray) => {
@ -85,9 +86,11 @@ exports.ensureArray = (maybeArray) => {
/** /**
* Ensures `message.from` is base58 encoded * Ensures `message.from` is base58 encoded
* @param {object} message *
* @param {String} peerId * @template {Object} T
* @return {object} * @param {T} message
* @param {string} [peerId]
* @return {T & {from?: string, peerId?: string }}
*/ */
exports.normalizeInRpcMessage = (message, peerId) => { exports.normalizeInRpcMessage = (message, peerId) => {
const m = Object.assign({}, message) const m = Object.assign({}, message)
@ -101,8 +104,10 @@ exports.normalizeInRpcMessage = (message, peerId) => {
} }
/** /**
* @param {object} message * @template {Object} T
* @return {object} *
* @param {T} message
* @return {T & {from?: Uint8Array, data?: Uint8Array}}
*/ */
exports.normalizeOutRpcMessage = (message) => { exports.normalizeOutRpcMessage = (message) => {
const m = Object.assign({}, message) const m = Object.assign({}, message)