vuejs / vuex-router-sync

Effortlessly keep vue-router and vuex store in sync.
MIT License
2.52k stars 125 forks source link

route state not compatible with typing definition from vue router #84

Open axe-me opened 6 years ago

axe-me commented 6 years ago
  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 commented 6 years ago

i will just shim it for now i guess,

import { Route } from "vue-router";
export interface RouteState extends Route {
  from: Route;
}
LinusBorg commented 6 years ago

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

posva commented 6 years ago

There's no from in Route type

axe-me commented 6 years ago

@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.

posva commented 6 years ago

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