diff --git a/lib/create-promise.js b/lib/create-promise.js index c32eb87..4b10c0b 100644 --- a/lib/create-promise.js +++ b/lib/create-promise.js @@ -1,10 +1,22 @@ 'use strict' +/** + * @callback PromiseResolve + * @param {any|PromiseLike} value + * @returns {void} + */ + +/** + * @callback PromiseReject + * @param {any} reason + * @returns {void} + */ + /** * @typedef PromiseObject * @property {Promise} promise - * @property {PromiseConstructor["resolve"]} resolve - * @property {PromiseConstructor["reject"]} reject + * @property {PromiseResolve} resolve + * @property {PromiseReject} reject */ /** @@ -12,8 +24,8 @@ */ function createPromise () { /** - * @type {PromiseObject} - */ + * @type {PromiseObject} + */ const obj = { resolve: null, reject: null, diff --git a/lib/is-bundled-or-typescript-plugin.js b/lib/is-bundled-or-typescript-plugin.js index f72438e..42003dd 100644 --- a/lib/is-bundled-or-typescript-plugin.js +++ b/lib/is-bundled-or-typescript-plugin.js @@ -7,12 +7,15 @@ */ /** - * @param {unknown} plugin + * @param {any} maybeBundledOrTypescriptPlugin * @returns {plugin is BundledOrTypescriptPlugin} */ - -function isBundledOrTypescriptPlugin (plugin) { - return plugin !== null && typeof plugin === 'object' && typeof plugin.default === 'function' +function isBundledOrTypescriptPlugin (maybeBundledOrTypescriptPlugin) { + return ( + maybeBundledOrTypescriptPlugin !== null && + typeof maybeBundledOrTypescriptPlugin === 'object' && + typeof maybeBundledOrTypescriptPlugin.default === 'function' + ) } module.exports = { diff --git a/lib/validate-plugin.js b/lib/validate-plugin.js index 4006ca4..374ee56 100644 --- a/lib/validate-plugin.js +++ b/lib/validate-plugin.js @@ -3,19 +3,20 @@ const { AVV_ERR_PLUGIN_NOT_VALID } = require('./errors') /** - * @param {unknown} plugin + * @param {any} maybePlugin * @throws {AVV_ERR_PLUGIN_NOT_VALID} - * @returns {Function} + * + * @returns {asserts plugin is Function|PromiseLike} */ -function validatePlugin (plugin) { +function validatePlugin (maybePlugin) { // validate if plugin is a function or Promise - if (!(plugin && (typeof plugin === 'function' || typeof plugin.then === 'function'))) { - if (Array.isArray(plugin)) { + if (!(maybePlugin && (typeof maybePlugin === 'function' || typeof maybePlugin.then === 'function'))) { + if (Array.isArray(maybePlugin)) { throw new AVV_ERR_PLUGIN_NOT_VALID('array') - } else if (plugin === null) { + } else if (maybePlugin === null) { throw new AVV_ERR_PLUGIN_NOT_VALID('null') } else { - throw new AVV_ERR_PLUGIN_NOT_VALID(typeof plugin) + throw new AVV_ERR_PLUGIN_NOT_VALID(typeof maybePlugin) } } }