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

feat: Switch routable props type over to an xor #50

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

rschristian
Copy link
Member

This change ensures the user sets either path or default for a route, but never both.

Previously, the types erroneously allowed you to set neither &/or both; setting neither made it a dead route, never to be used, and setting both is simply redundant.


TS's error message isn't great, if the user sets neither, they'll be met with the following which only mentions the latter half of the XOR:

Type '{ component: () => Element; }' is not assignable to type 'IntrinsicAttributes & (RouteProps<{ component: () => Element; }> & Partial<{ component: () => Element; }>)'.
  Type '{ component: () => Element; }' is not assignable to type 'IntrinsicAttributes & { path?: never; default: boolean; } & { component: AnyComponent<{ component: () => Element; }>; } & Partial<{ component: () => Element; }>'.
    Property 'default' is missing in type '{ component: () => Element; }' but required in type '{ path?: never; default: boolean; }'.

Related information:

  * router.d.ts#34,20: 'default' is declared here.

 (tsserver 2322)

Don't think we can do anything about this though.

Co-authored-by: Munawwar <[email protected]>
@rschristian rschristian merged commit bcbc031 into main Nov 5, 2024
1 check passed
@rschristian rschristian deleted the types/routable-props branch November 5, 2024 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants