From 4499a752a51c9b97334e5b83cfd7fbfdfa3b2dab Mon Sep 17 00:00:00 2001 From: Shi Yan Date: Thu, 17 Nov 2016 15:08:46 +0800 Subject: [PATCH 1/2] Fixed LocationDescriptor and pathOrLoc types. --- react-router/react-router.d.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/react-router/react-router.d.ts b/react-router/react-router.d.ts index 321adf9bb7..80a071f18d 100644 --- a/react-router/react-router.d.ts +++ b/react-router/react-router.d.ts @@ -28,8 +28,15 @@ declare namespace ReactRouter { type ParseQueryString = (queryString: H.QueryString) => H.Query + type LocationDescriptor = { + pathname?: H.Pathname + query?: H.Query + hash?: H.Hash + state?: H.LocationState + } + interface RedirectFunction { - (location: H.LocationDescriptor): void; + (location: LocationDescriptor): void; /** * @deprecated `replaceState(state, pathname, query) is deprecated; Use `replace(location)` with a location descriptor instead. http://tiny.cc/router-isActivedeprecated */ @@ -116,9 +123,7 @@ declare namespace ReactRouter { activeStyle?: React.CSSProperties activeClassName?: string onlyActiveOnIndex?: boolean - to: RoutePattern | H.LocationDescriptor - query?: H.Query - state?: H.LocationState + to: RoutePattern | LocationDescriptor | ((...args: any[]) => LocationDescriptor) } interface Link extends React.ComponentClass {} interface LinkElement extends React.ReactElement {} @@ -216,7 +221,7 @@ declare namespace ReactRouter { interface RouterOnContext extends H.History { setRouteLeaveHook(route: PlainRoute, hook?: RouteHook): () => void; - isActive(pathOrLoc: H.LocationDescriptor, indexOnly?: boolean): boolean; + isActive(pathOrLoc: H.Path | LocationDescriptor, indexOnly?: boolean): boolean; } /* mixins */ @@ -244,15 +249,15 @@ declare namespace ReactRouter { // https://github.com/reactjs/react-router/blob/v2.4.0/upgrade-guides/v2.4.0.md interface InjectedRouter { - push: (pathOrLoc: H.LocationDescriptor) => void - replace: (pathOrLoc: H.LocationDescriptor) => void + push: (pathOrLoc: H.Path | LocationDescriptor) => void + replace: (pathOrLoc: H.Path | LocationDescriptor) => void go: (n: number) => void goBack: () => void goForward: () => void setRouteLeaveHook(route: PlainRoute, callback: RouteHook): void createPath(path: H.Path, query?: H.Query): H.Path createHref(path: H.Path, query?: H.Query): H.Href - isActive: (pathOrLoc: H.LocationDescriptor, indexOnly?: boolean) => boolean + isActive: (pathOrLoc: H.Path | LocationDescriptor, indexOnly?: boolean) => boolean } function withRouter | React.StatelessComponent | React.PureComponent>(component: C): C @@ -520,7 +525,8 @@ declare module "react-router" { export type LeaveHook = ReactRouter.LeaveHook export type ParseQueryString = ReactRouter.ParseQueryString export type RedirectFunction = ReactRouter.RedirectFunction - export type RouteComponentProps = ReactRouter.RouteComponentProps; + export type RouteComponentProps = ReactRouter.RouteComponentProps + export type RouteConfig = ReactRouter.RouteConfig export type RouteHook = ReactRouter.RouteHook export type StringifyQuery = ReactRouter.StringifyQuery export type RouterListener = ReactRouter.RouterListener From d4b2e37e1c71085aeb69401a8ccd45c1a4c36b74 Mon Sep 17 00:00:00 2001 From: Shi Yan Date: Thu, 17 Nov 2016 21:43:53 +0800 Subject: [PATCH 2/2] Export LocationDescriptor --- react-router/react-router.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/react-router/react-router.d.ts b/react-router/react-router.d.ts index 80a071f18d..930273bf7f 100644 --- a/react-router/react-router.d.ts +++ b/react-router/react-router.d.ts @@ -524,6 +524,7 @@ declare module "react-router" { export type EnterHook = ReactRouter.EnterHook export type LeaveHook = ReactRouter.LeaveHook export type ParseQueryString = ReactRouter.ParseQueryString + export type LocationDescriptor = ReactRouter.LocationDescriptor export type RedirectFunction = ReactRouter.RedirectFunction export type RouteComponentProps = ReactRouter.RouteComponentProps export type RouteConfig = ReactRouter.RouteConfig