@dr.pogodin/js-utils 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,4 +9,4 @@
9
9
  * @returns Resolves to the result of the successful `action` execution;
10
10
  * or rejects with the error from the last faileda attempt.
11
11
  */
12
- export default function withRetries(action: () => unknown, maxRetries?: number, interval?: number): Promise<any>;
12
+ export default function withRetries<T>(action: () => T, maxRetries?: number, interval?: number): Promise<Awaited<T>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dr.pogodin/js-utils",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "Collection of JavaScript (TypeScript) utilities.",
5
5
  "main": "build/index",
6
6
  "react-native": "src/index",
@@ -37,8 +37,6 @@
37
37
  "@tsconfig/recommended": "^1.0.3",
38
38
  "@tsd/typescript": "^5.3.3",
39
39
  "@types/jest": "^29.5.12",
40
- "@typescript-eslint/eslint-plugin": "^6.21.0",
41
- "@typescript-eslint/parser": "^6.21.0",
42
40
  "babel-jest": "^29.7.0",
43
41
  "eslint": "^8.56.0",
44
42
  "eslint-config-airbnb-base": "^15.0.0",
@@ -49,6 +47,7 @@
49
47
  "jest-runner-tsd": "^6.0.0",
50
48
  "rimraf": "^5.0.5",
51
49
  "tsd-lite": "^0.8.2",
52
- "typescript": "^5.3.3"
50
+ "typescript": "^5.3.3",
51
+ "typescript-eslint": "^7.0.2"
53
52
  }
54
53
  }
@@ -11,16 +11,16 @@ import { timer } from './time';
11
11
  * @returns Resolves to the result of the successful `action` execution;
12
12
  * or rejects with the error from the last faileda attempt.
13
13
  */
14
- export default async function withRetries(
15
- action: () => unknown,
14
+ export default async function withRetries<T>(
15
+ action: () => T,
16
16
  maxRetries = 3,
17
17
  interval = 300,
18
- ) {
18
+ ): Promise<Awaited<T>> {
19
19
  /* eslint-disable no-await-in-loop */
20
20
  for (let n = 1; ; ++n) {
21
21
  try {
22
22
  const res = action();
23
- return res instanceof Promise ? await res : res;
23
+ return res instanceof Promise ? await res : (res as Awaited<T>);
24
24
  } catch (error) {
25
25
  if (n < maxRetries) await timer(interval);
26
26
  else throw error;