Skip to content

Commit fb9a377

Browse files
committed
fix type usePromise
1 parent 409de20 commit fb9a377

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@atomico/hooks",
33
"description": "Series of utilities in hooks format to extend the operation of Atomico",
4-
"version": "3.33.4",
4+
"version": "3.33.5",
55
"type": "module",
66
"workspaces": [
77
"src/**/*"

src/use-promise/use-promise.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ export const Status = {
1414
*/
1515
const initalState = () => [, ""];
1616
/**
17+
* @template {()=>Promise<any>} T
1718
* @example
1819
* ```js
1920
* const [executePromise, setExecutePromise] = useState();
2021
* const [ result, status ] = usePromise(()=>fetch("./any").then(res=>res.json()),executePromise);
2122
* ```
22-
* @param {()=>Promise<any>} promise -
23+
* @param {T} promise -
2324
* @param {boolean} run
2425
* @param {any[]} [args]
25-
* @returns {State}
26+
* @returns {T extends (...args:any[])=>Promise<infer R> ? State<R> : State<any> }
2627
*/
2728
export function usePromise(promise, run, args = []) {
2829
const [state, setState] = useState(initalState);
@@ -50,7 +51,10 @@ export function usePromise(promise, run, args = []) {
5051

5152
/**@typedef {Status["quiet"]|Status["pending"]|Status["fulfilled"]|Status["rejected"]} PromiseStatus */
5253

53-
/**@typedef {[any,PromiseStatus]} State */
54+
/**
55+
* @template T
56+
* @typedef {[T,PromiseStatus]} State
57+
**/
5458

5559
/**
5660
* @typedef {Object} Status

0 commit comments

Comments
 (0)