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'
module.exports = {
OPEN: 'open',
CLOSING: 'closing',
CLOSED: 'closed'
OPEN: /** @type {'open'} */('open'),
CLOSING: /** @type {'closing'} */('closing'),
CLOSED: /** @type {'closed'} */('closed')
}

View File

@ -13,7 +13,7 @@ exports.SignaturePolicy = {
* * Enforce the fields to be present, 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:
* * 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.
* * 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.
*
* @param {any} maybeArray
* @returns {Array}
* @template T
* @param {T|T[]} maybeArray
* @returns {T[]}
* @private
*/
exports.ensureArray = (maybeArray) => {
@ -85,9 +86,11 @@ exports.ensureArray = (maybeArray) => {
/**
* Ensures `message.from` is base58 encoded
* @param {object} message
* @param {String} peerId
* @return {object}
*
* @template {Object} T
* @param {T} message
* @param {string} [peerId]
* @return {T & {from?: string, peerId?: string }}
*/
exports.normalizeInRpcMessage = (message, peerId) => {
const m = Object.assign({}, message)
@ -101,8 +104,10 @@ exports.normalizeInRpcMessage = (message, peerId) => {
}
/**
* @param {object} message
* @return {object}
* @template {Object} T
*
* @param {T} message
* @return {T & {from?: Uint8Array, data?: Uint8Array}}
*/
exports.normalizeOutRpcMessage = (message) => {
const m = Object.assign({}, message)