Hacker News new | ask | show | jobs
by gherkinnn 1485 days ago
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.

1 comments

That's an interesting idea. Cheers.