Skip to content

Commit 3b6fcf5

Browse files
committed
refactor: update AsyncDataWrapper to exclude non-Promise functions
1 parent 464cfe6 commit 3b6fcf5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ type AsyncDataResult<T> = AsyncData<T, Error>;
1010
/**
1111
* Transforms an object's Promise-returning functions into functions compatible with useAsyncData.
1212
*
13+
* Only includes functions that return Promises; other properties are excluded.
14+
*
1315
* For each function in the object:
1416
* - If the function returns a Promise and takes no arguments, it becomes a function that accepts optional AsyncDataOptions.
1517
* - If the function returns a Promise and takes arguments, it becomes a function that accepts an argsSupplier and optional AsyncDataOptions.
1618
*
17-
* This allows you to use the functions within a Nuxt application, leveraging the reactivity and data fetching capabilities of useAsyncData.
18-
*
1919
* @template T - The type of the object.
2020
*/
2121
export type AsyncDataWrapper<T> = {
22-
[K in keyof T]: T[K] extends (...args: infer Args) => Promise<infer R>
22+
[K in keyof T as T[K] extends (...args: any[]) => Promise<any>
23+
? K
24+
: never]: T[K] extends (...args: infer Args) => Promise<infer R>
2325
? Args extends []
2426
? /**
2527
* Functions without arguments.

0 commit comments

Comments
 (0)