Losing the type between the client and server

VVolks10/12/2022
Hello everyone, I am new to tRPC and the magic of types in typescript so I am looking for ideas as to what is happening, the client is receiving any type instead of a string
VVolks10/12/2022
I doubt this is a bug, but I have no idea where to go for.
VVolks10/12/2022
This is on the client
(property) onSuccess?: ((data: {
    id: any;
    exists: any;
    name: any;
    email: string;
}, variables: {
    provider?: any;
    presignupEmail?: string | undefined;
    email: string;
    userID: string;
}, context: unknown) => unknown) | undefined


And this is on the server

(method) ProcedureBuilder<{ _config: RootConfig<{ ctx: { user?: undefined; } | { user: { uid: string; email: string; }; }; meta: {}; errorShape: DefaultErrorShape; transformer: CombinedDataTransformer; }>; ... 5 more ...; _output_out: typeof unsetMarker; }>.mutation<{
    id: string;
    exists: boolean;
    name: string | undefined;
    email: string;
}>(resolver: (opts: ResolveOptions<{
    _config: RootConfig<{
        ctx: {
            user?: undefined;
        } | {
            user: {
                uid: string;
                email: string;
            };
        };
        meta: {};
        errorShape: DefaultErrorShape;
        transformer: CombinedDataTransformer;
    }>;
    ... 5 more ...;
    _output_out: typeof unsetMarker;
}>) => MaybePromise<...>): BuildProcedure<...>
Mutation procedure
Mmarminge10/12/2022
Do you have strict mode? Are you using any data transformers?
VVolks10/14/2022
Hey @julius, I am using strict mode and I am using superjson. I am currently debugging on a reproducable repo first, but with a stripped down setup the types are working, so I am super confused at the moment
VVolks10/14/2022
Do you maybe have any pointers at the top of your head that can break types between projects. I basically have a monorepo

apps/
   - backend with trpc that exports app router
   - nextjs site that imports the app router


I just import the type from ../apps/backend/src/trpc.ts
VVolks10/14/2022
I'll keep debugging and close this if I find the culprit
Mmarminge10/14/2022
Not really, is the repo public?
VVolks10/18/2022
I have a minimal repository that closely mimics my real project which is unfortunately commercial and private, but I cannot for the life of me replicate the issue I am having in the real project @julius

For example

export const sessionContext = async ({
  req,
}: NodeHTTPCreateContextFnOptions<IncomingMessage, ServerResponse>) => {
  try {
    if (
      req.headers.authorization &&
      req.headers.authorization.split(" ")[0] === "Bearer"
    ) {
      const token = req.headers.authorization.split(" ")[1] as string;
      const decodedToken = await firebaseAdmin.auth().verifyIdToken(token);

      if (!decodedToken.email) {
        return {};
      }

      return {
        user: {
          uid: decodedToken.uid,
          email: decodedToken.email,
        },
      };
    }
    return {};
  } catch (error) {
    return {};
  }
};

export type Context = inferAsyncReturnType<typeof sessionContext>;


In my main project it has any types like displayed bellow but in my demo project it correctly has the uid and email as strings

(alias) type AppRouter = Router<RouterDef<RootConfig<{
    ctx: {
        user?: undefined;
    } | {
        user: {
            uid: any;
            email: any;
        };
    };
}>, {
    ...;
}, {
    ...;
}>> & {
    ...;
}
VVolks10/18/2022
So I thought that the types might be incorrect all together but if I do
VVolks10/18/2022
export const sessionContext = async ({
  req,
}: NodeHTTPCreateContextFnOptions<IncomingMessage, ServerResponse>) => {
  return {
    user: {
      uid: "test",
      email: "test",
    },
  };
};

export type Context = inferAsyncReturnType<typeof sessionContext>;


It gets inferred to

(alias) type AppRouter = Router<RouterDef<RootConfig<{
    ctx: {
        user: {
            uid: string;
            email: string;
        };
    };
}
VVolks10/18/2022
The type is correct on the server but gets inferred to any in the client
VVolks10/18/2022
But as you can see the types do get across
VVolks10/18/2022
Just some are any
VVolks10/18/2022
I have absolutely no clue as to what is happening
VVolks10/18/2022
Also the inferred type of my mutation has the same issue

type test = {
    id: any;
    exists: any;
    name: any;
    email: string;
}


But on the server the types are all okay

(method) ProcedureBuilder<{ _config: RootConfig<{ ctx: { user?: undefined; } | { user: { uid: string; email: string; }; }; meta: {}; errorShape: DefaultErrorShape; transformer: CombinedDataTransformer; }>; ... 5 more ...; _output_out: typeof unsetMarker; }>.mutation<{
    id: string;
    exists: boolean;
    name: string | undefined;
    email: string;
}>(resolver: (opts: ResolveOptions<{
Mmarminge10/18/2022
might be invalid tsconfig? or do you use the same in the repro?
VVolks10/18/2022
Both are the same, strict mode is on
VVolks10/18/2022
But the types are getting through to the client, just for some reason some types are lost and inferred to any
VVolks10/18/2022
Thats why I am super confused
Mmarminge10/18/2022
yea if you cant provide a repro i really cant help you since ive never seen this before
VVolks10/18/2022
Yeah I'll try to get it reproduced and push it to gh
VVolks10/21/2022
Hey @julius, tried my best to create a simple reproducible repository that reflects my issue. I added a readme that clarifies the issue further, here is the repo

https://github.com/Nikola-Milovic/monorepo-trpc-issue


I know this is a tall ask to check out but thank you nonetheless
VVolks10/21/2022
Inside packages/config are the tsconfig files and they all inherit from the base.json which defines the strict: true