Replies: 2 comments 1 reply
-
We managed to self roll this, if anyone is interested: import ziggyRoute from 'ziggy-js'
import type { RouteName, RouteParams } from 'ziggy-js'
type RemoveStringFromUnion<T> = T extends T ? (string & {} extends T ? never : T) : never
export type StrictRouteName = RemoveStringFromUnion<RouteName>
export function route<T extends StrictRouteName>(name: T, parameters?: RouteParams<T>, absolute?: boolean) {
return ziggyRoute(name, parameters, absolute)
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
I really like this idea but I have this nagging feeling that there's some reason I can't think of that we need to allow strings that we might think aren't valid route names 🙃 I wonder if there's any way to make this strictness optional? In the meantime your solution is really clean, and if we implement this I'm going to come back and refer to it. Thanks! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
I'm really happy about the added TypeScript support.
I wanted to ask if it would be possible to make the
route()
function to only accept validRouteName
and then error if it's not in the route list?This is the case for example for
momentum-trail
, which is a Ziggy wrapper.Having TypeScript yell at you, when you had a typo in the route name or when you refactored some names was really helpful in that case. :)
Beta Was this translation helpful? Give feedback.
All reactions