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):
Β
TypeScript is complaining:
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 }
}
},
})
7 Replies
If I understand correctly, tRPC (or TS) can't figure out that I'm returning a potential union?
{ success: false, validationErrors: ValidationError } | { success: true }
full error message, it seems that the union is detected but conflicts with
InferLast
π€Could you share the error as a code block? That file wonβt display on mobile
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; }'
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
that's the plan!
yeah I'm on strict π
I cast the type for now.