Ahmed Eid
Ahmed Eid3y ago

somehow when move typed function out of the router files, frontend infer type to be any ?

this is inferred corrected since they are in the same file.
getX: t.procedure.query(() => {
return getX()
})

function getX(): X{
...
}
getX: t.procedure.query(() => {
return getX()
})

function getX(): X{
...
}
getX: t.procedure.query(() => {
return getX()
})

export function getX(): X{ << moving this out of the file breaks the typing.
...
}
getX: t.procedure.query(() => {
return getX()
})

export function getX(): X{ << moving this out of the file breaks the typing.
...
}
6 Replies
Ahmed Eid
Ahmed Eid3y ago
which is a very weird issue.
sachin
sachin2y ago
not sure, probably unrelated to trpc
ItsWendell
ItsWendell2y ago
@Ahmed Eid any solution found?
volks
volks2y ago
What exactly do you refer as typing is broken? I think I got the same issue and my types result to any I made a repo that reproduces my issue, not sure its the same https://stackoverflow.com/questions/74185198/typescript-losing-zod-and-trpc-types-across-monorepo-projects-types-result-in
Stack Overflow
Typescript, losing Zod and tRPC types across monorepo projects, typ...
I am in a bit of a weird situation. For the past 2 weeks I've been trying to debug as to why I am losing types between my projects inside a monorepo. My backend exposes the types that my client use...
Ahmed Eid
Ahmed Eid2y ago
@ItsWendell I think I resolved it, if you're still facing this issue please let me know I think I can help you out.
ItsWendell
ItsWendell2y ago
I have a simar issue with a turbo repository, where 'second hand' types are infered as any, e.g. I have a package with the TRPC API, which might return types from an external package. I use the TRPC package types in our app, but all types that are infered from external packages are any, all types that I give directly are fine. One solution I have is to use references in tsconfig like this:
{
"references": [
{
"path": "../../packages/api-service"
}
]
}
{
"references": [
{
"path": "../../packages/api-service"
}
]
}
BUT I believe this might have performance impact + it's annoying to have to think about adding this to every package that consumes the API service types