route search params type not working when it's a union and have parent search params #2977
-
Hey, so let's say I have the following validateSearch: z.union([
z.object({
test11: z.string(),
test12: z.string(),
}),
z.object({
test13: z.string(),
test14: z.string(),
}),
]), Now, when using
const test: {
test11: string;
test12: string;
} | {
test13: string;
test14: string;
} On runtime, it behaves as expected, meaning it will respect the schema provided and will throw errors accordingly, it's just the typescript types that are behaving incorrectly, so I'm not sure this is a bug or that we're not supposed to use unions.. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I found that having the following validateSearch: z.union([
z.object({
test11: z.string(),
test12: z.string(),
test13: z.never().optional(),
test14: z.never().optional(),
}),
z.object({
test11: z.never().optional(),
test12: z.never().optional(),
test13: z.string(),
test14: z.string(),
}),
]), Now, search params with the above schema will get merged as expected with parent search params, so if for example the parent have a schema like so: const test: {
redirect?: string | undefined;
test11: string;
test12: string;
test13?: undefined;
test14?: undefined;
} | {
redirect?: string | undefined;
test13: string;
test14: string;
test11?: undefined;
test12?: undefined;
} before it was only: const test: {
redirect?: string | undefined;
} |
Beta Was this translation helpful? Give feedback.
-
https://github.com/TanStack/router/releases/tag/v1.87.12 should fix this |
Beta Was this translation helpful? Give feedback.
https://github.com/TanStack/router/releases/tag/v1.87.12 should fix this