Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit af0b7f3

Browse files
authored
fix: types for withTimeoutOptions (#3422)
#3407 has introduced regression in type inference for `withTimeoutOptions` function which end up referring to `Fn<Args, R>` type which was declared in other file https://github.com/ipfs/js-ipfs/pull/3407/files#diff-722621abc3ed4edc6ab202fdf684f1607c261394b95da6b3ec79748711056f20 I think TS has this strange WTF where when it can't figure out when JS file is a module it will treat it as if everything is loaded in the same scope. I think that caused `withTimeoutOptions` not to report errors but silently fail and infer return function as `any`. This change fixes that by removes `Fn` type all together, as it seemed like unnecessary complexity. Unfortunately nothing seemed to have caught this regression because we set [`noImplicitAny`](https://www.typescriptlang.org/tsconfig#noImplicitAny) to `false` given that many of our dependencies are untyped.
1 parent 79c2c80 commit af0b7f3

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

Diff for: packages/ipfs-core-utils/src/index.js

-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
11
'use strict'
2-
3-
/**
4-
* @template {any[]} ARGS
5-
* @template R
6-
* @typedef {(...args: ARGS) => R} Fn
7-
*/

Diff for: packages/ipfs-core-utils/src/with-timeout-option.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ const parseDuration = require('parse-duration').default
77
const { TimeoutError } = require('./errors')
88

99
/**
10-
* @template {any[]} ARGS
10+
* @template {any[]} Args
1111
* @template {Promise<any> | AsyncIterable<any>} R - The return type of `fn`
12-
* @param {Fn<ARGS, R>} fn
12+
* @param {(...args:Args) => R} fn
1313
* @param {number} [optionsArgIndex]
14-
* @returns {Fn<ARGS, R>}
14+
* @returns {(...args:Args) => R}
1515
*/
1616
function withTimeoutOption (fn, optionsArgIndex) {
1717
// eslint-disable-next-line
18-
return /** @returns {R} */(/** @type {ARGS} */...args) => {
18+
return /** @returns {R} */(/** @type {Args} */...args) => {
1919
const options = args[optionsArgIndex == null ? args.length - 1 : optionsArgIndex]
2020
if (!options || !options.timeout) return fn(...args)
2121

0 commit comments

Comments
 (0)