kitbagjs / router

A type safe router for vuejs
MIT License
131 stars 1 forks source link

Fix `RouterRoute` type so that `isRoute` type guard works correctly when given a `RouterRoute` #199

Closed pleek91 closed 2 weeks ago

pleek91 commented 2 weeks ago

Description

The isRoute type guard was functionally sound and types work just fine. But RouterRoute produced a type that was too specific and to wide. So when passing a RouterRoute into isRoute the types conflicted and effectively didn't narrow properly. A few changes were necessary to fix this.

  1. Update Route type to default to a string for the key rather than any. Because any & 'key' is still any. But string & 'key' is 'key'. Which is what we want.
  2. Remove Omit utility from RouterRoute declaration. This produces a much simpler type and one that typescript can reason about without evaluating it.
  3. Replace all DeepReadonly types with Readonly to produce simpler types that typescript can reason about more easily (and produce much more readable types)
  4. Remove all uses of readonly (to satisfy the DeepReadonly removal)

3 & 4 were not strictly necessary. I had a working version that still used the readonly types, but everything looks much better without it. I want to revisit this in a follow up PR. For now I've marked the one test that covered the readonly pieces as fails.

netlify[bot] commented 2 weeks ago

Deploy Preview for kitbag-router ready!

Name Link
Latest commit 0e82a1562bc8d609c5c08a19ab17425b1c796547
Latest deploy log https://app.netlify.com/sites/kitbag-router/deploys/6674dc741c88920008f6ade1
Deploy Preview https://deploy-preview-199--kitbag-router.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.