marshallswain / feathers-pinia

Connect your Feathers API to the elegant data store for Vue
52 stars 22 forks source link

Recommandation for useGet returned object type/interface #154

Open barnacker opened 8 months ago

barnacker commented 8 months ago

How would one go about typing the object returned by: https://feathers-pinia.pages.dev/services/use-get.html#returned-object

I was planning to do something like:

const myStuff: UseGetResult = myService.useGet(id)

And then I would dig as needed depending on the case.

I looked into the code and found that the returned object didnt have an interface such as:

useGet(id: MaybeRef<Id | null>, params?: MaybeRef<UseGetParams>): UseGetResult

But currently is implemented this way:

useGet(id: MaybeRef<Id | null>, params?: MaybeRef<UseGetParams>): {
    params: UseGetParams;
    isSsr: boolean;
    data: SvcModel<Svc> | null;
    ids: Id[];
    getFromStore: any;
    get: () => Promise<AnyData>;
    request: {
        then: <TResult1 = AnyData, TResult2 = never>(onfulfilled?: ((value: AnyData) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<TResult1 | TResult2>;
        catch: <TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined) => Promise<AnyData | TResult>;
        finally: (onfinally?: (() => void) | null | undefined) => Promise<AnyData>;
        readonly [Symbol.toStringTag]: string;
    } | null;
    requestCount: number;
    queryWhen: (_queryWhenFn: () => boolean) => void;
    isPending: boolean;
    hasBeenRequested: boolean;
    hasLoaded: boolean;
    error: any;
    clearError: () => null;
};