vuex-router-sync icon indicating copy to clipboard operation
vuex-router-sync copied to clipboard

route state not compatible with typing definition from vue router

Open axe-me opened this issue 7 years ago • 5 comments
trafficstars

  import { Route } from "vue-router";

  @Watch("route")
  onRouteChanged(currRoute: Route) {
    if (currRoute.meta.parentRoute) {
      // got ts error at this line saying: 'Property 'from' does not exist on type 'Route'.'
      this.buttonText = currRoute.from.name;
      this.routeName = null;
      this.show = true;
    } else {
      this.show = false;
    }
  }

prob should define a route typing for the state in this library?

axe-me avatar Jun 27 '18 16:06 axe-me

i will just shim it for now i guess,

import { Route } from "vue-router";
export interface RouteState extends Route {
  from: Route;
}

axe-me avatar Jun 27 '18 17:06 axe-me

This issue seems to be about vue-router, not vuex-router-sync?

LinusBorg avatar Jul 03 '18 20:07 LinusBorg

There's no from in Route type

posva avatar Jul 03 '18 20:07 posva

@posva that is the problem, no from in route type, but the store state has it: https://github.com/vuejs/vuex-router-sync/blob/master/src/index.js#L71 , and @LinusBorg I don't think this is a issue for vue-router, since this library bind the from property on the route object.

thus I believe we should shim it in the type definition file here https://github.com/vuejs/vuex-router-sync/blob/master/types/index.d.ts

i can make a PR if you guys think this is the right way to do, i have to shim it in my app anyway.

axe-me avatar Jul 03 '18 21:07 axe-me

Ah, I see but don't add it to the Route type since it's only available in store module. Worst case is creating a new type and exporting it

posva avatar Jul 04 '18 06:07 posva