Skip to content

Commit

Permalink
fix(flow,types): fix props type
Browse files Browse the repository at this point in the history
  • Loading branch information
zrh122 committed Jul 16, 2019
1 parent b7715dc commit 4f7e2a0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions flow/declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ declare type RouterOptions = {

declare type RedirectOption = RawLocation | ((to: Route) => RawLocation)

type RoutePropsFunction = (route: Route) => Object

declare type RouteConfig = {
path: string;
name?: string;
Expand All @@ -58,7 +60,7 @@ declare type RouteConfig = {
children?: Array<RouteConfig>;
beforeEnter?: NavigationGuard;
meta?: any;
props?: boolean | Object | Function;
props?: boolean | Object | RoutePropsFunction | Dictionary<boolean | Object | RoutePropsFunction>;
caseSensitive?: boolean;
pathToRegexpOptions?: PathToRegexpOptions;
}
Expand All @@ -74,7 +76,7 @@ declare type RouteRecord = {
matchAs: ?string;
beforeEnter: ?NavigationGuard;
meta: any;
props: boolean | Object | Function | Dictionary<boolean | Object | Function>;
props: Dictionary<boolean | Object | RoutePropsFunction>;
}

declare type Location = {
Expand Down
1 change: 1 addition & 0 deletions src/create-route-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function addRouteRecord (
route.props == null
? {}
: route.components
// $flow-disable-line
? route.props
: { default: route.props }
}
Expand Down
4 changes: 2 additions & 2 deletions types/router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export interface RouteConfig {
children?: RouteConfig[];
meta?: any;
beforeEnter?: NavigationGuard;
props?: boolean | Object | RoutePropsFunction;
props?: boolean | Object | RoutePropsFunction | Dictionary<boolean | Object | RoutePropsFunction>;
caseSensitive?: boolean;
pathToRegexpOptions?: PathToRegexpOptions;
}
Expand All @@ -101,7 +101,7 @@ export interface RouteRecord {
redirect: (location: RawLocation) => void,
next: () => void
) => any;
props: boolean | Object | RoutePropsFunction | Dictionary<boolean | Object | RoutePropsFunction>;
props: Dictionary<boolean | Object | RoutePropsFunction>;
}

export interface Location {
Expand Down
8 changes: 8 additions & 0 deletions types/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ const router = new VueRouter({
from.params;
next({ name: "home" });
next();
},
props: {
default: true,
bar: { id: 123 },
asyncComponent: (route: Route) => route.params
}
},
{
Expand Down Expand Up @@ -121,6 +126,9 @@ matched.forEach(m => {
const name: string | undefined = m.name;
const parant: RouteRecord | undefined = m.parent;
const redirect: RedirectOption | undefined = m.redirect;
const props: {
[key: string]: boolean | Object | ((route: Route) => Object)
} = m.props;
});

const unregister = router.beforeEach((to, from, next) => {
Expand Down

0 comments on commit 4f7e2a0

Please sign in to comment.