Skip to content

feat(typescript): add branded type for creating routes#862

Merged
bakerkretzmar merged 4 commits intotighten:2.xfrom
pataar:better_typing
Sep 13, 2025
Merged

feat(typescript): add branded type for creating routes#862
bakerkretzmar merged 4 commits intotighten:2.xfrom
pataar:better_typing

Conversation

@pataar
Copy link
Contributor

@pataar pataar commented Sep 4, 2025

This adds a branded type for RouteUrl. This way you can create custom Anchor components, custom functions that are typed to a RouteUrl.

e.g.

function redirect(route: RouteUrl){
   // redirect logic
}

const route = router('home');

if(condition){
  redirect(route);
  redirect("https://random.url"); // error
}

@bakerkretzmar
Copy link
Collaborator

Very cool, thanks! I took out the export of KnownRouteName because I don't think it's necessary for this PR's functionality and I'm still very hesitant to expose Ziggy's types publicly in case we rename things or accidentally lock ourselves into something. If that was actually necessary for something here and I missed it please let me know.

@bakerkretzmar bakerkretzmar merged commit 9cdd300 into tighten:2.x Sep 13, 2025
28 checks passed
@pataar
Copy link
Contributor Author

pataar commented Sep 14, 2025

That's all good. Had some personal use cases for it. But I can extract it with Parameters<> as well.

Thanks for merging!

@pataar pataar deleted the better_typing branch September 15, 2025 13:35
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