Skip to content

Commit e1e549f

Browse files
committed
fix(flow,types): fix props type
1 parent 8ac478f commit e1e549f

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

flow/declarations.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ declare type RouterOptions = {
4848

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

51+
type RoutePropsFunction = (route: Route) => Object
52+
5153
declare type RouteConfig = {
5254
path: string;
5355
name?: string;
@@ -58,7 +60,7 @@ declare type RouteConfig = {
5860
children?: Array<RouteConfig>;
5961
beforeEnter?: NavigationGuard;
6062
meta?: any;
61-
props?: boolean | Object | Function;
63+
props?: boolean | Object | RoutePropsFunction | Dictionary<boolean | Object | RoutePropsFunction>;
6264
caseSensitive?: boolean;
6365
pathToRegexpOptions?: PathToRegexpOptions;
6466
}
@@ -74,7 +76,7 @@ declare type RouteRecord = {
7476
matchAs: ?string;
7577
beforeEnter: ?NavigationGuard;
7678
meta: any;
77-
props: boolean | Object | Function | Dictionary<boolean | Object | Function>;
79+
props: Dictionary<boolean | Object | RoutePropsFunction>;
7880
}
7981

8082
declare type Location = {

src/create-route-map.js

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function addRouteRecord (
8484
props: route.props == null
8585
? {}
8686
: route.components
87+
// $flow-disable-line
8788
? route.props
8889
: { default: route.props }
8990
}

types/router.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export interface RouteConfig {
8181
children?: RouteConfig[];
8282
meta?: any;
8383
beforeEnter?: NavigationGuard;
84-
props?: boolean | Object | RoutePropsFunction;
84+
props?: boolean | Object | RoutePropsFunction | Dictionary<boolean | Object | RoutePropsFunction>;
8585
caseSensitive?: boolean;
8686
pathToRegexpOptions?: PathToRegexpOptions;
8787
}
@@ -101,7 +101,7 @@ export interface RouteRecord {
101101
redirect: (location: RawLocation) => void,
102102
next: () => void
103103
) => any;
104-
props: boolean | Object | RoutePropsFunction | Dictionary<boolean | Object | RoutePropsFunction>;
104+
props: Dictionary<boolean | Object | RoutePropsFunction>;
105105
}
106106

107107
export interface Location {

types/test/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ const router = new VueRouter({
8080
from.params;
8181
next({ name: "home" });
8282
next();
83+
},
84+
props: {
85+
default: true,
86+
bar: { id: 123 },
87+
asyncComponent: (route: Route) => route.params
8388
}
8489
},
8590
{
@@ -121,6 +126,9 @@ matched.forEach(m => {
121126
const name: string | undefined = m.name;
122127
const parant: RouteRecord | undefined = m.parent;
123128
const redirect: RedirectOption | undefined = m.redirect;
129+
const props: {
130+
[key: string]: boolean | Object | ((route: Route) => Object)
131+
} = m.props;
124132
});
125133

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

0 commit comments

Comments
 (0)