Skip to content

Commit

Permalink
Fix types by adding some anys in there
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 4, 2021
1 parent 1572953 commit 55cbddb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* @typedef {(error?: Error|null|undefined, ...output: unknown[]) => void} Callback
* @typedef {(...input: unknown[]) => unknown} Middleware
* @typedef {(error?: Error|null|undefined, ...output: any[]) => void} Callback
* @typedef {(...input: any[]) => any} Middleware
*
* @typedef {(...input: unknown[]) => void} Run Call all middleware.
* @typedef {(...input: any[]) => void} Run Call all middleware.
* @typedef {(fn: Middleware) => Pipeline} Use Add `fn` (middleware) to the list.
* @typedef {{run: Run, use: Use}} Pipeline
*/
Expand All @@ -24,7 +24,6 @@ export function trough() {
function run(...values) {
let middlewareIndex = -1
/** @type {Callback} */
// @ts-expect-error Assume it’s a callback.
const callback = values.pop()

if (typeof callback !== 'function') {
Expand All @@ -37,7 +36,7 @@ export function trough() {
* Run the next `fn`, or we’re done.
*
* @param {Error|null|undefined} error
* @param {unknown[]} output
* @param {any[]} output
*/
function next(error, ...output) {
const fn = fns[++middlewareIndex]
Expand Down Expand Up @@ -96,12 +95,12 @@ export function wrap(middleware, callback) {

/**
* Call `middleware`.
* @param {unknown[]} parameters
* @param {any[]} parameters
* @returns {void}
*/
function wrapped(...parameters) {
const fnExpectsCallback = middleware.length > parameters.length
/** @type {unknown} */
/** @type {any} */
let result

if (fnExpectsCallback) {
Expand All @@ -127,7 +126,6 @@ export function wrap(middleware, callback) {

if (!fnExpectsCallback) {
if (result instanceof Promise) {
// type-coverage:ignore-next-line Assume it’s a `Promise<unknown>`
result.then(then, done)
} else if (result instanceof Error) {
done(result)
Expand All @@ -151,7 +149,7 @@ export function wrap(middleware, callback) {
/**
* Call `done` with one value.
*
* @param {unknown} [value]
* @param {any} [value]
*/
function then(value) {
done(null, value)
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
"ignoreCatch": true,
"#": "some nessecary `any`s",
"ignoreFiles": [
"index.js",
"index.d.ts"
]
}
}

0 comments on commit 55cbddb

Please sign in to comment.