Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zod discriminated union ts issues #2824

Open
dragansavevski opened this issue Nov 21, 2024 · 0 comments
Open

Zod discriminated union ts issues #2824

dragansavevski opened this issue Nov 21, 2024 · 0 comments
Labels
types Changes to the typescript types

Comments

@dragansavevski
Copy link

Which project does this relate to?

Router

Describe the bug

When trying to have a zod discriminated union I cannot achieve full type safety. See the example app (__root.tsx and about.tsx). Basically I tried 3 approaches. Setting the undesired parameters to undefined, never and omitting them. Each of these approaches causes a different error:

  1. If I use z.never type issues occur at About 2 link
  2. If I use z.undefined type issues in the search middleware in the about route
  3. If I omit them and not have them at all the loader cannot be typed.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-qm8eay?file=src%2Froutes%2F__root.tsx,src%2Froutes%2Fabout.tsx&preset=node

Steps to Reproduce the Bug or Issue

See the about.tsx component and its search params.
See the about.tsx component and the links inside.

Expected behavior

I expect to have a proper discriminated union type.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 131.0.6778.86

Additional context

No response

@SeanCassiere SeanCassiere added start Everything about TanStack Start types Changes to the typescript types and removed start Everything about TanStack Start labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types Changes to the typescript types
Projects
None yet
Development

No branches or pull requests

2 participants