mercurius-js / mercurius-typescript

TypeScript usage examples and "mercurius-codegen" for Mercurius

Home Page:https://mercurius.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot find name DeepPartial

stolinski opened this issue · comments

Using via codegen.yml

The generated ts looks like

/**
 * @deprecated
 * Use "Resolvers" root object instead. If you wish to get "IResolvers", add "typesPrefix: I" to your config.
 */
export type IResolvers<ContextType = Context> = Resolvers<ContextType>;


    type Loader<TReturn, TObj, TParams, TContext> = (
        queries: Array<{
          obj: TObj;
          params: TParams;
        }>,
        context: TContext & {
          reply: import("fastify").FastifyReply;
        }
      ) => Promise<Array<DeepPartial<TReturn>>>;
    type LoaderResolver<TReturn, TObj, TParams, TContext> = 
    Loader<TReturn, TObj, TParams, TContext> | {
        loader: Loader<TReturn, TObj, TParams, TContext>;
        opts?:{
            cache?:boolean
        };
        
....

Things are working well with the exception of DeepPartial not being defined anywhere.

Since the package in designed primarily for programmatic usage, the DeepPartial is created in-line via calling it that way, but this specific issue is easy to fix either exporting DeepPartial from mercurius-codegen package, which I'm going to do in the next release later today, or an immediate workaround adding the types via codegen add plugin:

export type DeepPartial<T> = T extends Function
    ? T
    : T extends Array<infer U>
    ? _DeepPartialArray<U>
    : T extends object
    ? _DeepPartialObject<T>
    : T | undefined;
  
interface _DeepPartialArray<T> extends Array<DeepPartial<T>> {}
type _DeepPartialObject<T> = { [P in keyof T]?: DeepPartial<T[P]> };

fixed in v1.3.8, thanks 👍