jgoux
jgouxβ€’16mo ago

No overload matches this call when outputting unions

Hello there πŸ‘‹, I have this simple procedure (we're not fully migrated on v10 yet, using interop):
export const databaseValidateUrl = trpc
.router<Context>()
.query('database.validateUrl', {
input: z.object({ url: z.string() }),
resolve: ({ input: { url } }) => {
const result = new ConnectionString(url)

if (result.validationErrors) {
return {
success: false,
validationErrors: result.validationErrors,
}
} else {
return { success: true }
}
},
})
export const databaseValidateUrl = trpc
.router<Context>()
.query('database.validateUrl', {
input: z.object({ url: z.string() }),
resolve: ({ input: { url } }) => {
const result = new ConnectionString(url)

if (result.validationErrors) {
return {
success: false,
validationErrors: result.validationErrors,
}
} else {
return { success: true }
}
},
})
Β  TypeScript is complaining:
7 Replies
jgoux
jgouxβ€’16mo ago
If I understand correctly, tRPC (or TS) can't figure out that I'm returning a potential union? { success: false, validationErrors: ValidationError } | { success: true }
jgoux
jgouxβ€’16mo ago
jgoux
jgouxβ€’16mo ago
full error message, it seems that the union is detected but conflicts with InferLast πŸ€”
Nick
Nickβ€’16mo ago
Could you share the error as a code block? That file won’t display on mobile
jgoux
jgouxβ€’16mo ago
No overload matches this call.
Overload 1 of 3, '(path: "database.validateUrl", procedure: CreateProcedureWithInputOutputParser<{ user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }, {}, { url: string; }, { ...; }, { ...; }, unknown>): Router<...>', gave the following error.
Type '({ input: { url } }: { ctx: { user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }; input: { url: string; }; type: ProcedureType; }) => { ...; } | { ...; }' is not assignable to type 'ProcedureResolver<{ user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }, { url: string; }, InferLast<{ success: boolean; validationErrors: ValidationErrorType; }>>'.
Type '{ success: boolean; validationErrors: ValidationErrorType; } | { success: boolean; validationErrors?: undefined; }' is not assignable to type 'InferLast<{ success: boolean; validationErrors: ValidationErrorType; }> | Promise<InferLast<{ success: boolean; validationErrors: ValidationErrorType; }>>'.
Type '{ success: boolean; validationErrors?: undefined; }' is not assignable to type 'InferLast<{ success: boolean; validationErrors: ValidationErrorType; }> | Promise<InferLast<{ success: boolean; validationErrors: ValidationErrorType; }>>'.
Type '{ success: boolean; validationErrors?: undefined; }' is not assignable to type 'InferLast<{ success: boolean; validationErrors: ValidationErrorType; }>'.
Type '{ success: boolean; validationErrors?: undefined; }' is not assignable to type '{ success: boolean; validationErrors: ValidationErrorType; }'.
Types of property 'validationErrors' are incompatible.
Type 'undefined' is not assignable to type 'ValidationErrorType'.
No overload matches this call.
Overload 1 of 3, '(path: "database.validateUrl", procedure: CreateProcedureWithInputOutputParser<{ user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }, {}, { url: string; }, { ...; }, { ...; }, unknown>): Router<...>', gave the following error.
Type '({ input: { url } }: { ctx: { user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }; input: { url: string; }; type: ProcedureType; }) => { ...; } | { ...; }' is not assignable to type 'ProcedureResolver<{ user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }, { url: string; }, InferLast<{ success: boolean; validationErrors: ValidationErrorType; }>>'.
Type '{ success: boolean; validationErrors: ValidationErrorType; } | { success: boolean; validationErrors?: undefined; }' is not assignable to type 'InferLast<{ success: boolean; validationErrors: ValidationErrorType; }> | Promise<InferLast<{ success: boolean; validationErrors: ValidationErrorType; }>>'.
Type '{ success: boolean; validationErrors?: undefined; }' is not assignable to type 'InferLast<{ success: boolean; validationErrors: ValidationErrorType; }> | Promise<InferLast<{ success: boolean; validationErrors: ValidationErrorType; }>>'.
Type '{ success: boolean; validationErrors?: undefined; }' is not assignable to type 'InferLast<{ success: boolean; validationErrors: ValidationErrorType; }>'.
Type '{ success: boolean; validationErrors?: undefined; }' is not assignable to type '{ success: boolean; validationErrors: ValidationErrorType; }'.
Types of property 'validationErrors' are incompatible.
Type 'undefined' is not assignable to type 'ValidationErrorType'.
Overload 2 of 3, '(path: "database.validateUrl", procedure: CreateProcedureWithInput<{ user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }, {}, { url: string; }, { ...; }>): Router<...>', gave the following error.
Type '({ input: { url } }: { ctx: { user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }; input: { url: string; }; type: ProcedureType; }) => { ...; } | { ...; }' is not assignable to type 'ProcedureResolver<{ user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }, { url: string; }, InferLast<{ success: boolean; validationErrors: ValidationErrorType; }>>'.
Overload 2 of 3, '(path: "database.validateUrl", procedure: CreateProcedureWithInput<{ user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }, {}, { url: string; }, { ...; }>): Router<...>', gave the following error.
Type '({ input: { url } }: { ctx: { user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }; input: { url: string; }; type: ProcedureType; }) => { ...; } | { ...; }' is not assignable to type 'ProcedureResolver<{ user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }, { url: string; }, InferLast<{ success: boolean; validationErrors: ValidationErrorType; }>>'.
Overload 3 of 3, '(path: "database.validateUrl", procedure: CreateProcedureWithoutInput<{ user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }, {}, { success: boolean; validationErrors: ValidationErrorType; }, unknown>): Router<...>', gave the following error.
Type '({ input: { url } }: { ctx: { user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }; input: { url: string; }; type: ProcedureType; }) => { ...; } | { ...; }' is not assignable to type 'ProcedureResolver<{ user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }, undefined, InferLast<{ success: boolean; validationErrors: ValidationErrorType; }>>'.
Types of parameters '__0' and 'opts' are incompatible.
Type '{ ctx: { user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }; input: undefined; type: ProcedureType; }' is not assignable to type '{ ctx: { user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }; input: { url: string; }; type: ProcedureType; }'.
Types of property 'input' are incompatible.
Type 'undefined' is not assignable to type '{ url: string; }'
Overload 3 of 3, '(path: "database.validateUrl", procedure: CreateProcedureWithoutInput<{ user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }, {}, { success: boolean; validationErrors: ValidationErrorType; }, unknown>): Router<...>', gave the following error.
Type '({ input: { url } }: { ctx: { user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }; input: { url: string; }; type: ProcedureType; }) => { ...; } | { ...; }' is not assignable to type 'ProcedureResolver<{ user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }, undefined, InferLast<{ success: boolean; validationErrors: ValidationErrorType; }>>'.
Types of parameters '__0' and 'opts' are incompatible.
Type '{ ctx: { user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }; input: undefined; type: ProcedureType; }' is not assignable to type '{ ctx: { user: { id: string; email: string; sub: string; entry?: string | undefined; role: "SUPERUSER" | "ADMIN" | "USER"; }; userId: string; }; input: { url: string; }; type: ProcedureType; }'.
Types of property 'input' are incompatible.
Type 'undefined' is not assignable to type '{ url: string; }'
It was to long for a single code block πŸ˜…
Nick
Nickβ€’16mo ago
Do you have strict:true in your tsconfig? You could be right it's related to interop, you should migrate this to v10 and see how the errors change, as interop will be going away in v11 anyway and that's not far out
jgoux
jgouxβ€’16mo ago
that's the plan! yeah I'm on strict πŸ™‚ I cast the type for now.
More Posts
[help] Uncaught (in promise) TRPCClientError: Property description must be an object: uAfter building on linux, I visit the site. And Chrome console shows this error. But if I build on myHow can I make tRPC+NextJs APIs faster? (db and functions region is already same)Hi, I have migrated my website backend (https://clubofcoders.com) from NestJs + Prisma + Cloud Run tSuperjson "undefined"When returning a list from the db with a ton of potential undefined fields, superjson just crams a tThrowing fastify errors when using fastify adapterHello, I'm using `fastifyTRPCPlugin` from `@trpc/server/adapters/fastify` and trying to throw errorsConfused about createProxySSGHelpersIf you can use this helper inside of `getServerSideProps` without having `ssr: true` what is the difHow to check if data is being prefetched?What is a method to check if ssg prefetching actually occurs? Through the network tab?How can I access ctx from inside of a procedure?``` const appRouter = t.router({ helloTab: t.procedure.input(z.object({ url: z.string().url() })).Async User Call in `createContext` (context.ts) or in `isAuthed` (in trpc.ts)Hi all! Should I be getting the user in all requests via createContext in the following async call `'req' of undefined in onError of express middlewareI've recently noticed that I get a bunch of errors regarding req object missing in ctx for onError pMutations and Queries in React Contexts causing unexpected behaviorsIn my organization, we recently moved to put all of our mutations/queries into React Contexts and ou