3 ms·
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
by gherkinnn 4y 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/C4TwDgpgBASg9gV2NAvAWAFBSgHygIgHp9Ns8iATAQwGcALAIzioCcKStcDDr6nWKhKhQC2ASwB2HMt16NmbQnABuEFsrEQA7tK4ADHrXkCeEYFTEAbQgBIA3hIQiGagL57S+w3wWCKZi2t7R2c3QhE4FggPTnJCGjNgSQBzGg5MAGM4CRpgKCoALlhEZCgUWSN+RX9zK0IARgAmAGYOLJy8hiL4JFQKnxMawIaW8MiIdIx23KgAGUkAazKoAAo7DLorCiiJABooOiiAM1ci9c3LbYgJbogqDOAAOTh-fcOII+6SiFcASlv7k8XqgAHyrTwAHioB2OKDs7xOIPOWx2rghQhBmF+QA https://www.typescriptlang.org/play?jsx=4#code/C4TwDgpgBASg9...
TS' string literal types are powerful.
https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types 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.
- onion2k 4y agoThat's an interesting idea. Cheers.