diff --git a/types/redux-first-router/index.d.ts b/types/redux-first-router/index.d.ts index 96ce9e489b..22dce972c4 100644 --- a/types/redux-first-router/index.d.ts +++ b/types/redux-first-router/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: Valbrand // viggyfresh // janb87 +// corydeppen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 @@ -21,21 +22,24 @@ export type StateGetter = () => object; export type RouteString = string; -export type RouteThunk = (dispatch: Dispatch, getState: StateGetter) => any | Promise; +export type RouteThunk = ( + dispatch: Dispatch, + getState: StateGetter +) => any | Promise; -export interface RouteObject { - path: string; +export type RouteObject = TKeys & { capitalizedWords?: boolean; - toPath?(param: string, key?: string): string; - fromPath?(path: string, key?: string): string; - thunk?: RouteThunk; navKey?: string; -} + path: string; + thunk?: RouteThunk; + fromPath?(path: string, key?: string): string; + toPath?(param: string, key?: string): string; +}; -export type Route = RouteString | RouteObject; +export type Route = RouteString | RouteObject; -export interface RoutesMap { - [key: string]: Route; +export interface RoutesMap { + [key: string]: Route; } export interface ReceivedAction { @@ -127,14 +131,25 @@ export interface HistoryLocation { export type HistoryAction = string; -export type Listener = (location: HistoryLocation, action: HistoryAction) => void; +export type Listener = ( + location: HistoryLocation, + action: HistoryAction +) => void; export type ScrollBehavior = object; export interface Router { - getStateForActionOriginal(action: object, state: Nullable): Nullable; - getStateForAction(action: object, state: Nullable): Nullable; - getPathAndParamsForState(state: object): { path: Nullable, params: Nullable }; + getStateForActionOriginal( + action: object, + state: Nullable + ): Nullable; + getStateForAction( + action: object, + state: Nullable + ): Nullable; + getPathAndParamsForState( + state: object + ): { path: Nullable; params: Nullable }; getActionForPathAndParams(path: string): Nullable; } @@ -164,14 +179,14 @@ export interface NavigatorsConfig { navigationAction: Nullable, route: Nullable ): object; - navigationToAction( + navigationToAction( navigators: Navigators, - store: Store, + store: Store, routesMap: RoutesMap, action: object ): { - action: object, - navigationAction: Nullable + action: object; + navigationAction: Nullable; }; } @@ -180,9 +195,9 @@ export interface Options { location?: string | SelectLocationState; notFoundPath?: string; scrollTop?: boolean; - onBeforeChange?(dispatch: Dispatch, getState: StateGetter): void; - onAfterChange?(dispatch: Dispatch, getState: StateGetter): void; - onBackNext?(dispatch: Dispatch, getState: StateGetter): void; + onBeforeChange?(dispatch: Dispatch, getState: StateGetter): void; + onAfterChange?(dispatch: Dispatch, getState: StateGetter): void; + onBackNext?(dispatch: Dispatch, getState: StateGetter): void; restoreScroll?(history: History): ScrollBehavior; initialDispatch?: boolean; querySerializer?: QuerySerializer; @@ -196,7 +211,11 @@ export type ScrollUpdater = (performedByUser: boolean) => void; export const NOT_FOUND: '@@redux-first-router/NOT_FOUND'; -export function actionToPath(action: ReceivedAction, routesMap: RoutesMap, querySerializer?: QuerySerializer): string; +export function actionToPath( + action: ReceivedAction, + routesMap: RoutesMap, + querySerializer?: QuerySerializer +): string; export function back(): void; @@ -206,12 +225,16 @@ export function canGoBack(): boolean; export function canGoForward(): boolean; -export function connectRoutes(history: History, routesMap: RoutesMap, options?: Options): { - reducer: Reducer, - middleware: Middleware, - thunk(store: Store): Promise>, - enhancer: GenericStoreEnhancer, - initialDispatch?(): void +export function connectRoutes( + history: History, + routesMap: RoutesMap, + options?: Options +): { + reducer: Reducer; + middleware: Middleware; + thunk(store: Store): Promise>; + enhancer: GenericStoreEnhancer; + initialDispatch?(): void; }; export function go(n: number): void; @@ -224,7 +247,10 @@ export function next(): void; export function nextPath(): string | void; -export function pathToAction(pathname: string, routesMap: RoutesMap): ReceivedAction; +export function pathToAction( + pathname: string, + routesMap: RoutesMap +): ReceivedAction; export function prevPath(): string | void; diff --git a/types/redux-first-router/redux-first-router-tests.ts b/types/redux-first-router/redux-first-router-tests.ts index 39b00c7a94..3c9e69a82e 100644 --- a/types/redux-first-router/redux-first-router-tests.ts +++ b/types/redux-first-router/redux-first-router-tests.ts @@ -9,16 +9,16 @@ import { QuerySerializer } from 'redux-first-router'; import { - createStore, - applyMiddleware, - Middleware, - MiddlewareAPI, - Store, - Dispatch, - compose, - Action, - GenericStoreEnhancer, - StoreEnhancerStoreCreator + createStore, + applyMiddleware, + Middleware, + MiddlewareAPI, + Store, + Dispatch, + compose, + Action, + GenericStoreEnhancer, + StoreEnhancerStoreCreator } from 'redux'; import { History } from 'history'; @@ -28,24 +28,31 @@ declare var history: History; type State = LocationState; type StoreCreator = StoreEnhancerStoreCreator; -const routesMap = { - HOME: '/' +const routesMap: RoutesMap<{ role: string }> = { + HOME: '/', + ADMIN: { + path: '/admin', + role: 'admin' + } }; const { - reducer, - middleware, - enhancer, - initialDispatch + reducer, + middleware, + enhancer, + initialDispatch } = connectRoutes(history, routesMap, { - initialDispatch: false + initialDispatch: false }); const dumbMiddleware: Middleware = store => next => action => next(action); const composedMiddleware = applyMiddleware(middleware, dumbMiddleware); -const storeEnhancer = compose(enhancer, composedMiddleware); +const storeEnhancer = compose( + enhancer, + composedMiddleware +); const store = createStore(reducer, storeEnhancer);