S
SolidJS2mo ago
aryzing

Create resource TS types fail when using `{ refetching }`

When creating a resource,
const [value, { refetch }] = createResource(
source,
async function (source, { refetching }): Promise<Example> { /* ... */ }
);
const [value, { refetch }] = createResource(
source,
async function (source, { refetching }): Promise<Example> { /* ... */ }
);
the type of value will be Resource<unknown> instead of Example. However, if we delete the second arg of the fetcher and use the 1 arg version, the return type is inferred correctly.
const [value, { refetch }] = createResource(
source,
async function (source): Promise<Example> { /* ... */ }
);
const [value, { refetch }] = createResource(
source,
async function (source): Promise<Example> { /* ... */ }
);
Now value will correctly be inferred as Resource<Example>. Is this an issue?
1 Reply
aryzing
aryzingOP2mo ago
Was able to fix it by explicitly setting the types,
createResource<
ConnectionState,
Network
>(/*...*/)
createResource<
ConnectionState,
Network
>(/*...*/)
Want results from more Discord servers?
Add your server