Skip to content

fix(flow,types): fix props type #2768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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