From c4e3656a590f5fe8fa8f3abdb387233ecee79767 Mon Sep 17 00:00:00 2001 From: Vignesh Venkataraman Date: Fri, 4 Aug 2017 15:54:23 -0700 Subject: [PATCH] [redux-first-router] Update type definitions to v1.9 (#18562) * Update redux-first-router typings with API changes as of v1.9.8 * Scrub trailing commas * Fix style of author declarations * Carefully exact-match typings to flow typings * Revert Params and Payload to object type --- types/redux-first-router/index.d.ts | 63 +++++++++++++++---- .../redux-first-router-tests.ts | 7 ++- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/types/redux-first-router/index.d.ts b/types/redux-first-router/index.d.ts index e1f62e1014..5acbe08493 100644 --- a/types/redux-first-router/index.d.ts +++ b/types/redux-first-router/index.d.ts @@ -1,6 +1,7 @@ -// Type definitions for redux-first-router 1.4 +// Type definitions for redux-first-router 1.9 // Project: https://github.com/faceyspacey/redux-first-router#readme // Definitions by: Valbrand +// viggyfresh // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -38,9 +39,23 @@ export interface RoutesMap { export interface ReceivedAction { type: string; - payload: object; + payload: Payload; meta?: object; - navKey?: string | null; + query?: object; + search?: string; + navKey?: Nullable; +} + +export interface ReceivedActionMeta { + type: string; + payload: Payload; + query?: object; + navKey?: Nullable; + meta: { + notFoundPath?: string; + query?: object; + search?: string; + }; } export interface HistoryData { @@ -52,13 +67,17 @@ export interface HistoryData { export interface Location { pathname: string; type: string; - payload: object; + payload: Payload; + query?: object; + search?: string; } export interface LocationState { pathname: string; type: string; - payload: object; + payload: Payload; + query?: object; + search?: string; prev: Location; kind: Nullable; history: Nullable; @@ -80,7 +99,7 @@ export interface NavigationAction { routeName?: string; actions?: NavigationAction[]; action?: NavigationAction; - params?: object; + params?: Params; meta?: object; } @@ -88,17 +107,21 @@ export interface Meta { location: ActionMetaLocation; notFoundPath?: string; navigation?: NavigationAction; + query?: object; + search?: string; } export interface Action { type: string; - payload: object; + payload: Payload; meta: Meta; - navKey?: string; + query?: object; + navKey?: Nullable; } export interface HistoryLocation { pathname: string; + search?: string; } export type HistoryAction = string; @@ -110,7 +133,7 @@ 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 }; + getPathAndParamsForState(state: object): { path: Nullable, params: Nullable }; getActionForPathAndParams(path: string): Nullable; } @@ -122,6 +145,14 @@ export interface Navigators { [key: string]: Navigator; } +export type SelectLocationState = (state: object) => LocationState; +export type SelectTitleState = (state: object) => string; + +export interface QuerySerializer { + stringify(params: Params): string; + parse(queryString: string): object; +} + export interface NavigatorsConfig { navigators: Navigators; patchNavigators(navigators: Navigators): void; @@ -144,17 +175,22 @@ export interface NavigatorsConfig { } export interface Options { - title?: string; - location?: string; + title?: string | SelectTitleState; + 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; restoreScroll?(history: History): ScrollBehavior; + initialDispatch?: boolean; + querySerializer?: QuerySerializer; navigators?: NavigatorsConfig; } +export type Params = object; +export type Payload = object; + export type ScrollUpdater = (performedByUser: boolean) => void; export const NOT_FOUND: string; @@ -170,10 +206,11 @@ export function canGoBack(): boolean; export function canGoForward(): boolean; export function connectRoutes(history: History, routesMap: RoutesMap, options?: Options): { - reducer: Reducer + reducer: Reducer, middleware: Middleware, thunk(store: Store): Promise>, - enhancer: GenericStoreEnhancer + enhancer: GenericStoreEnhancer, + initialDispatch?(): void }; export function go(n: number): void; diff --git a/types/redux-first-router/redux-first-router-tests.ts b/types/redux-first-router/redux-first-router-tests.ts index aab3f8c2a0..fc913aebcf 100644 --- a/types/redux-first-router/redux-first-router-tests.ts +++ b/types/redux-first-router/redux-first-router-tests.ts @@ -26,8 +26,11 @@ const routesMap = { const { reducer, middleware, - enhancer -} = connectRoutes(history, routesMap); + enhancer, + initialDispatch +} = connectRoutes(history, routesMap, { + initialDispatch: false +}); const dumbMiddleware: Middleware = (store: MiddlewareAPI) => (next: Dispatch) => (action: Action) => { next(action);