T
tRPC

❓-help

standaloneMiddleware: Merge ctx/meta/input types

DDavid10/7/2023
Using standaloneMiddleware, it would be great to merge the types (ctx, input, meta) with what is already there when passing that middleware. In our case:
experimental_standaloneMiddleware<{ ctx: { user: { id: number } } }>()
experimental_standaloneMiddleware<{ ctx: { user: { id: number } } }>()
this is because we want to be sure user.id exists in the context before allowing the usage of this middleware, but when returning like this: next({ ctx: { ...ctx, newProp: '' } }) you would still want the context type to be merged with the original so your queries and mutations get the complete context.

Looking for more? Join the community!