-
|
Hello everyone ! I'm using a contract first oRPC setup, with my errors defined this way : const create = oc
.route({
method: "POST",
path: "/",
})
.errors(errors)
.input(createVehicleSchema)
.output(successSchema);My errors : import { type ErrorMap } from "@orpc/contract";
import * as z from "zod/v4";
export const errors: ErrorMap = {
INPUT_VALIDATION_FAILED: {
status: 422,
data: z.object({
fieldErrors: z.record(z.string(), z.array(z.string()).optional()),
formErrors: z.array(z.string()),
}),
},
};In the front I'm using tanstack query but the error is typed "never" : const createVehicleMutation = useMutation(
openapi.vehicles.create.mutationOptions({
onError: (error) => {
if (isDefinedError(error) && error.code === "INPUT_VALIDATION_FAILED") { // typescript: Property 'code' does not exist on type 'never'.
form.setErrorMap({
onSubmit: {
fields: error.data.fieldErrors,
},
});
}
});I'm in a Bun monorepo and somehow I feel it might comes from import quirk... isDefinedError<ErrorFromErrorMap<MergedErrorMap<Record<never, never>, MergedErrorMap<Record<never, never>, ErrorMap>>>>(error: ErrorFromErrorMap<MergedErrorMap<Record<never, never>, MergedErrorMap<Record<never, never>, ErrorMap>>>): error is neverAny help would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
|
Hi @FLchs! I'm Dosu and I’m helping the orpc team. Your error is typed as never because the error map isn't properly propagated to the client—TypeScript only sees an empty error map, so ErrorFromErrorMap collapses to never. This usually happens if the contract/router used to generate your OpenAPI client doesn't include your defined errors, or if there's an import quirk in your monorepo setup that causes type mismatches or dependency duplication (especially with Bun) [source]. To fix this:
This isn't a bug in oRPC, but a result of how TypeScript infers types from your contract and how your monorepo/bundler resolves modules. Once the client sees the correct error map, the error type will be inferred correctly and isDefinedError will work as expected. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
Can you help me create a minimal repro? |
Beta Was this translation helpful? Give feedback.
Here how you can define standalone ErrorMap correctly: