jgoux
jgouxβ€’2y 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
jgouxOPβ€’2y 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
jgouxOPβ€’2y ago
jgoux
jgouxOPβ€’2y ago
full error message, it seems that the union is detected but conflicts with InferLast πŸ€”
Nick
Nickβ€’2y ago
Could you share the error as a code block? That file won’t display on mobile
jgoux
jgouxOPβ€’2y 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β€’2y 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
jgouxOPβ€’2y ago
that's the plan! yeah I'm on strict πŸ™‚ I cast the type for now.