Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm curious about what you mean. There's no way to embed type information into a URL - every GET parameter is a string. Are you suggesting that visiting a link like /123 would go to the 'string: "123"' route, while clicking a <Link to={123}> would route you to 'number: "123"'? That would make deep linking in an app really hard to manage. I'm struggling to understand why you'd want to overload routes like that.


Generating a set of links from the routing as a union of strings as type Route. And a <Link /> component that only accepts an href of that type.

Like so: https://www.typescriptlang.org/play?jsx=4#code/C4TwDgpgBASg9...

TS' string literal types are powerful.

https://www.typescriptlang.org/docs/handbook/2/everyday-type...

edit: I did implement this a while back but found it gave me only so much additional value. Though I can imagine that large applications with dozens of developers might indeed benefit from type-safe routes to avoid dead links.


That's an interesting idea. Cheers.


I'm pretty sure what they are looking for is that something like a Link that takes a route name and a params object that are both typed.


This may be of interest: https://www.npmjs.com/package/hono




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: