Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Missing type declaration for createResource #31

Open
crymis opened this issue Aug 26, 2019 · 3 comments
Open

Missing type declaration for createResource #31

crymis opened this issue Aug 26, 2019 · 3 comments

Comments

@crymis
Copy link

crymis commented Aug 26, 2019

Correct me, if I'm missing something, but I can not use the useLoads function from a resource I declared.

Example

const partsResource = Loads.createResource<Part[]>({
  _namespace: 'parts',
  load: getParts,
  fooPart: getFooParts,
})

const partsLoader = partsResource.useLoads() // Property 'useLoads' does not exist on type '{ unstable_load: ({ id, args }?: LoadsSuspenderOpts | undefined) => Part[] | undefined; unstable_preload: ({ id, args }?: LoadsSuspenderOpts | undefined) => Part[] | undefined; }'.ts(2339)

Would be great if you could add the missing typings.

@jxom
Copy link
Owner

jxom commented Aug 27, 2019

Thanks for pointing this out. Will work on a fix soon.

@Kamahl19
Copy link

Kamahl19 commented Mar 5, 2020

Is there a fix coming?

@Kamahl19
Copy link

Kamahl19 commented Mar 5, 2020

I currently use this workaround

type ReactLoadsResource<Response, Err> = {
  useLoads: (
    loadsConfig?: LoadsConfig<Response, Err> | undefined
  ) => {
    isCached: boolean;
    isIdle: boolean;
    isPending: boolean;
    isPendingSlow: boolean;
    isResolved: boolean;
    isRejected: boolean;
    isReloading: boolean;
    isReloadingSlow: boolean;
    load: (..._args: any) => Promise<void | Response> | undefined;
    update:
      | ((..._args: any) => Promise<void | Response> | undefined)
      | ((..._args: any) => Promise<void | Response> | undefined)[]
      | undefined;
    reset: () => void;
    response: Response | undefined;
    error: Err | undefined;
    state: LoadingState;
  };
};

const resource = createResource<Data, Error>({
  context: 'data',
  fn: getData,
}) as ReactLoadsResource<Data, Error>;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants