-
-
Notifications
You must be signed in to change notification settings - Fork 984
Closed
Description
Describe the bug
Currently, ResourceActions
is typed as
export type ResourceActions<T, R = unknown> = {
mutate: Setter<T>;
refetch: (info?: R) => T | Promise<T> | undefined | null;
};
This means refetch
could be:
- A function that takes
info?: R
and returnsT
, OR - A
Promise<T>
, OR undefined
, ORnull
But looking at the actual implementation, refetch
is always a function:
{ refetch: info => runWithOwner(owner, () => load(info)), mutate: setValue }
I believe the intention with ResourceActions
was:
export type ResourceActions<T, R = unknown> = {
mutate: Setter<T>;
refetch: (info?: R) => (T | Promise<T> | undefined | null); // needed parentheses
};
Now it correctly indicates that refetch
is a function that takes info?: R
and will return T | Promise<T> | undefined | null
Your Example Website or App
https://playground.solidjs.com/anonymous/e5e44212-244e-41de-bd64-db7247e8fefe
Steps to Reproduce the Bug or Issue
- Create a resource:
const [data, {refetch}] = createResource(fn)
- Use the
refetch
as a Promise in some update function:
const updateData = () => refetch.catch(logError)
- Get bug
undefined has no property catch
Expected behavior
I expect that my IDE and linter can correctly tell me that I am using refetch
the right way, without having to test if it is a promise, or undefined, or null.
Screenshots or Videos
No response
Platform
- OS: [e.g. macOS, Windows, Linux]
- Browser: [e.g. Chrome, Safari, Firefox]
- Version: [e.g. 91.1]
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels