diff --git a/types/react-router-redux/index.d.ts b/types/react-router-redux/index.d.ts index 92b625be82..bebaab7562 100644 --- a/types/react-router-redux/index.d.ts +++ b/types/react-router-redux/index.d.ts @@ -1,18 +1,53 @@ -// Type definitions for react-router-redux 4.0 -// Project: https://github.com/rackt/react-router-redux -// Definitions by: Isman Usoh -// Noah Shipley -// Dimitri Rosenberg -// Karol Janyst -// Dovydas Navickas +// Type definitions for react-router-redux 5.0 +// Project: https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux +// Definitions by: Huy Nguyen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 +// TypeScript Version: 2.2 -import { Action, Middleware, Store } from "redux"; -import { History, Location, LocationDescriptor } from "history"; +import { + Store, + Dispatch, + Action, + Middleware +} from 'redux'; +import { + History, + Location, + Path, + LocationState, + LocationDescriptor +} from 'history'; +import * as React from 'react'; + +export interface ConnectedRouterProps { + store?: Store; + history?: History; +} +export class ConnectedRouter extends React.Component, {}> {} + +export const LOCATION_CHANGE: string; + +export interface RouterState { + location: Location | null; +} + +export function routerReducer(state?: RouterState, action?: RouterAction): RouterState; export const CALL_HISTORY_METHOD: string; -export const LOCATION_CHANGE: string; + +export function push(location: LocationDescriptor, state?: LocationState): RouterAction; +export function replace(location: LocationDescriptor, state?: LocationState): RouterAction; +export function go(n: number): RouterAction; +export function goBack(): RouterAction; +export function goForward(): RouterAction; + +export const routerAction: { + push: typeof push + replace: typeof replace + go: typeof go + goBack: typeof goBack + goForward: typeof goForward +}; export interface LocationActionPayload { method: string; @@ -20,44 +55,8 @@ export interface LocationActionPayload { } export interface RouterAction extends Action { - payload?: LocationActionPayload; + type: typeof CALL_HISTORY_METHOD; + payload: LocationActionPayload; } -type LocationAction = (nextLocation: LocationDescriptor) => RouterAction; -type GoAction = (n: number) => RouterAction; -type NavigateAction = () => RouterAction; - -export const push: LocationAction; -export const replace: LocationAction; -export const go: GoAction; -export const goBack: NavigateAction; -export const goForward: NavigateAction; - -interface RouteActions { - push: typeof push; - replace: typeof replace; - go: typeof go; - goForward: typeof goForward; - goBack: typeof goBack; -} - -export const routerActions: RouteActions; - -export interface RouterState { - locationBeforeTransitions: Location; -} - -export type DefaultSelectLocationState = (state: any) => RouterState; - -export interface SyncHistoryWithStoreOptions { - selectLocationState?: DefaultSelectLocationState; - adjustUrlOnReplay?: boolean; -} - -export interface HistoryUnsubscribe { - unsubscribe(): void; -} - -export function routerReducer(state?: RouterState, action?: Action): RouterState; -export function syncHistoryWithStore(history: History, store: Store, options?: SyncHistoryWithStoreOptions): History & HistoryUnsubscribe; export function routerMiddleware(history: History): Middleware; diff --git a/types/react-router-redux/react-router-redux-tests.tsx b/types/react-router-redux/react-router-redux-tests.tsx new file mode 100644 index 0000000000..b6927fb7bf --- /dev/null +++ b/types/react-router-redux/react-router-redux-tests.tsx @@ -0,0 +1,46 @@ +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; + +import { createStore, combineReducers, applyMiddleware, Reducer } from 'redux'; +import { Provider } from 'react-redux'; + +import createHistory from 'history/createBrowserHistory'; +import { Route } from 'react-router'; + +import { ConnectedRouter, routerReducer, routerMiddleware, push, RouterState } from 'react-router-redux'; + +// Create a history of your choosing (we're using a browser history in this case) +const history = createHistory(); + +// Build the middleware for intercepting and dispatching navigation actions +const middleware = routerMiddleware(history); + +interface State { + router: RouterState; +} + +// For testing, assume the router reducer is the only sub-reducer: +const reducers: Reducer = combineReducers({router: routerReducer}); + +// Add the reducer to your store on the `router` key +// Also apply our middleware for navigating +const store = createStore( + reducers, + applyMiddleware(middleware) +); + +const Home = () =>
Home
; +ReactDOM.render( + + { /* ConnectedRouter will use the store from Provider automatically */ } + +
+ +
+
+
, + document.getElementById('root') +); + +// Now you can dispatch navigation actions from anywhere! +store.dispatch(push('/foo')); diff --git a/types/react-router-redux/tsconfig.json b/types/react-router-redux/tsconfig.json index 7e9539f9dd..bd33709ea0 100644 --- a/types/react-router-redux/tsconfig.json +++ b/types/react-router-redux/tsconfig.json @@ -8,20 +8,17 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "jsx": "react", "baseUrl": "../", "typeRoots": [ - "../" + "../" ], - "paths": { - "history": ["history/v3"], - "history/*": ["history/v3/*"] - }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true }, "files": [ "index.d.ts", - "react-router-redux-tests.ts" + "react-router-redux-tests.tsx" ] } diff --git a/types/react-router-redux/tslint.json b/types/react-router-redux/tslint.json index 377cc837d4..f9e30021f4 100644 --- a/types/react-router-redux/tslint.json +++ b/types/react-router-redux/tslint.json @@ -1 +1,3 @@ -{ "extends": "../tslint.json" } +{ + "extends": "../tslint.json" +} diff --git a/types/react-router-redux/v3/index.d.ts b/types/react-router-redux/v3/index.d.ts index be706bdcc8..19473384a1 100644 --- a/types/react-router-redux/v3/index.d.ts +++ b/types/react-router-redux/v3/index.d.ts @@ -7,7 +7,6 @@ import * as Redux from "redux"; import * as History from "history"; - export const TRANSITION: string; export const UPDATE_LOCATION: string; diff --git a/types/react-router-redux/v4/index.d.ts b/types/react-router-redux/v4/index.d.ts new file mode 100644 index 0000000000..90d403da24 --- /dev/null +++ b/types/react-router-redux/v4/index.d.ts @@ -0,0 +1,63 @@ +// Type definitions for react-router-redux 4.0 +// Project: https://github.com/rackt/react-router-redux +// Definitions by: Isman Usoh , +// Noah Shipley , +// Dimitri Rosenberg , +// Karol Janyst , +// Dovydas Navickas +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +import { Action, Middleware, Store } from "redux"; +import { History, Location, LocationDescriptor } from "history"; + +export const CALL_HISTORY_METHOD: string; +export const LOCATION_CHANGE: string; + +export interface LocationActionPayload { + method: string; + args?: any[]; +} + +export interface RouterAction extends Action { + payload?: LocationActionPayload; +} + +type LocationAction = (nextLocation: LocationDescriptor) => RouterAction; +type GoAction = (n: number) => RouterAction; +type NavigateAction = () => RouterAction; + +export const push: LocationAction; +export const replace: LocationAction; +export const go: GoAction; +export const goBack: NavigateAction; +export const goForward: NavigateAction; + +interface RouteActions { + push: typeof push; + replace: typeof replace; + go: typeof go; + goForward: typeof goForward; + goBack: typeof goBack; +} + +export const routerActions: RouteActions; + +export interface RouterState { + locationBeforeTransitions: Location; +} + +export type DefaultSelectLocationState = (state: any) => RouterState; + +export interface SyncHistoryWithStoreOptions { + selectLocationState?: DefaultSelectLocationState; + adjustUrlOnReplay?: boolean; +} + +export interface HistoryUnsubscribe { + unsubscribe(): void; +} + +export function routerReducer(state?: RouterState, action?: Action): RouterState; +export function syncHistoryWithStore(history: History, store: Store, options?: SyncHistoryWithStoreOptions): History & HistoryUnsubscribe; +export function routerMiddleware(history: History): Middleware; diff --git a/types/react-router-redux/v4/package.json b/types/react-router-redux/v4/package.json new file mode 100644 index 0000000000..36ce503807 --- /dev/null +++ b/types/react-router-redux/v4/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "redux": "^3.6.0" + } +} diff --git a/types/react-router-redux/react-router-redux-tests.ts b/types/react-router-redux/v4/react-router-redux-tests.ts similarity index 100% rename from types/react-router-redux/react-router-redux-tests.ts rename to types/react-router-redux/v4/react-router-redux-tests.ts diff --git a/types/react-router-redux/v4/tsconfig.json b/types/react-router-redux/v4/tsconfig.json new file mode 100644 index 0000000000..83cf349881 --- /dev/null +++ b/types/react-router-redux/v4/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "paths": { + "history": ["history/v3"], + "history/*": ["history/v3/*"], + "react-router-redux": ["react-router-redux/v4"] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-router-redux-tests.ts" + ] +} diff --git a/types/react-router-redux/v4/tslint.json b/types/react-router-redux/v4/tslint.json new file mode 100644 index 0000000000..f05741c59b --- /dev/null +++ b/types/react-router-redux/v4/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "../tslint.json", + "rules": { + "forbidden-types": false + } +}