diff --git a/types/react-redux/index.d.ts b/types/react-redux/index.d.ts index 52cc28b9a51908..bc16194f0cc755 100644 --- a/types/react-redux/index.d.ts +++ b/types/react-redux/index.d.ts @@ -26,15 +26,15 @@ type StatelessComponent

= React.StatelessComponent

; type Component

= React.ComponentType

; type ReactNode = React.ReactNode; type Store = Redux.Store; -type Dispatch = Redux.Dispatch; +type Dispatch = Redux.Dispatch; type ActionCreator = Redux.ActionCreator; // Diff / Omit taken from https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-311923766 type Diff = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T]; type Omit = Pick>; -export interface DispatchProp { - dispatch?: Dispatch; +export interface DispatchProp { + dispatch?: Dispatch; } interface AdvancedComponentDecorator { @@ -76,11 +76,11 @@ export type InferableComponentEnhancer = * @param options */ export interface Connect { - (): InferableComponentEnhancer>; + (): InferableComponentEnhancer; ( mapStateToProps: MapStateToPropsParam - ): InferableComponentEnhancerWithProps & TOwnProps, TOwnProps>; + ): InferableComponentEnhancerWithProps; ( mapStateToProps: null | undefined, @@ -121,7 +121,7 @@ export interface Connect { mapDispatchToProps: null | undefined, mergeProps: null | undefined, options: Options - ): InferableComponentEnhancerWithProps & TStateProps, TOwnProps>; + ): InferableComponentEnhancerWithProps; ( mapStateToProps: null | undefined, @@ -161,14 +161,14 @@ interface MapStateToPropsFactory { type MapStateToPropsParam = MapStateToPropsFactory | MapStateToProps | null | undefined; interface MapDispatchToPropsFunction { - (dispatch: Dispatch, ownProps: TOwnProps): TDispatchProps; + (dispatch: Dispatch, ownProps: TOwnProps): TDispatchProps; } type MapDispatchToProps = MapDispatchToPropsFunction | TDispatchProps; interface MapDispatchToPropsFactory { - (dispatch: Dispatch, ownProps: TOwnProps): MapDispatchToProps; + (dispatch: Dispatch, ownProps: TOwnProps): MapDispatchToProps; } type MapDispatchToPropsParam = MapDispatchToPropsFactory | MapDispatchToProps; @@ -236,7 +236,7 @@ export declare function connectAdvanced { - (dispatch: Dispatch, factoryOptions: TFactoryOptions): Selector + (dispatch: Dispatch, factoryOptions: TFactoryOptions): Selector } export interface Selector { diff --git a/types/react-redux/package.json b/types/react-redux/package.json index 6d68bf2f9b10bf..7f5b19d45b96c5 100644 --- a/types/react-redux/package.json +++ b/types/react-redux/package.json @@ -1,6 +1,6 @@ { "private": true, "dependencies": { - "redux": "^3.6.0" + "redux": "^4.0.0" } } diff --git a/types/react-redux/react-redux-tests.tsx b/types/react-redux/react-redux-tests.tsx index 07b81ff082363e..367afedad6a5a8 100644 --- a/types/react-redux/react-redux-tests.tsx +++ b/types/react-redux/react-redux-tests.tsx @@ -1,7 +1,7 @@ import { Component, ReactElement } from 'react'; import * as React from 'react'; import * as ReactDOM from 'react-dom'; -import { Store, Dispatch, ActionCreator, createStore, bindActionCreators, ActionCreatorsMapObject } from 'redux'; +import { Store, Dispatch, AnyAction, ActionCreator, createStore, bindActionCreators, ActionCreatorsMapObject } from 'redux'; import { Connect, connect, createProvider, Provider, DispatchProp, MapStateToProps, Options } from 'react-redux'; import objectAssign = require('object-assign'); @@ -14,7 +14,7 @@ import objectAssign = require('object-assign'); // output of `connect` to make sure the signature is what is expected namespace Empty { - interface OwnProps { foo: string, dispatch: Dispatch } + interface OwnProps { foo: string, dispatch: Dispatch } class TestComponent extends Component {} @@ -42,7 +42,7 @@ namespace MapState { namespace MapStateWithDispatchProp { interface OwnProps { foo: string } - interface StateProps { bar: number, dispatch: Dispatch } + interface StateProps { bar: number, dispatch: Dispatch } class TestComponent extends Component {} @@ -250,7 +250,7 @@ namespace MapStateAndOptions { interface State { state: string; } interface OwnProps { foo: string } interface StateProps { bar: number } - interface DispatchProps { dispatch: Dispatch } + interface DispatchProps { dispatch: Dispatch } class TestComponent extends Component {} @@ -295,7 +295,7 @@ function mapStateToProps(state: CounterState) { } // Which action creators does it want to receive by props? -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { onIncrement: () => dispatch(increment()) }; @@ -327,7 +327,7 @@ connect( // with higher order functions using parameters connect( (initialState: CounterState, ownProps) => mapStateToProps, - (dispatch: Dispatch, ownProps) => mapDispatchToProps + (dispatch: Dispatch, ownProps) => mapDispatchToProps )(Counter); // only first argument connect( @@ -415,7 +415,7 @@ ReactDOM.render( // Inject just dispatch and don't listen to store -const AppWrap = (props: DispatchProp & { children?: React.ReactNode }) =>

+const AppWrap = (props: DispatchProp & { children?: React.ReactNode }) =>
const WrappedApp = connect()(AppWrap); @@ -446,7 +446,7 @@ connect(mapStateToProps2, actionCreators)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps2(dispatch: Dispatch) { +function mapDispatchToProps2(dispatch: Dispatch) { return { actions: bindActionCreators(actionCreators, dispatch) }; } @@ -458,7 +458,7 @@ connect(mapStateToProps2, mapDispatchToProps2)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps3(dispatch: Dispatch) { +function mapDispatchToProps3(dispatch: Dispatch) { return bindActionCreators({ addTodo }, dispatch); } @@ -470,7 +470,7 @@ connect(mapStateToProps2, mapDispatchToProps3)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps4(dispatch: Dispatch) { +function mapDispatchToProps4(dispatch: Dispatch) { return { todoActions: bindActionCreators(todoActionCreators, dispatch), counterActions: bindActionCreators(counterActionCreators, dispatch) @@ -485,7 +485,7 @@ connect(mapStateToProps2, mapDispatchToProps4)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps5(dispatch: Dispatch) { +function mapDispatchToProps5(dispatch: Dispatch) { return { actions: bindActionCreators(objectAssign({}, todoActionCreators, counterActionCreators), dispatch) }; @@ -499,7 +499,7 @@ connect(mapStateToProps2, mapDispatchToProps5)(TodoApp); // return { todos: state.todos }; //} -function mapDispatchToProps6(dispatch: Dispatch) { +function mapDispatchToProps6(dispatch: Dispatch) { return bindActionCreators(objectAssign({}, todoActionCreators, counterActionCreators), dispatch); } @@ -541,7 +541,7 @@ interface TestState { isLoaded: boolean; state1: number; } -class TestComponent extends Component, TestState> { } +class TestComponent extends Component { } const WrappedTestComponent = connect()(TestComponent); // return value of the connect()(TestComponent) is of the type TestComponent @@ -559,7 +559,7 @@ class NonComponent {} // stateless functions interface HelloMessageProps { - dispatch: Dispatch + dispatch: Dispatch name: string; } const HelloMessage: React.StatelessComponent = (props) => { @@ -585,7 +585,7 @@ namespace TestStatelessFunctionWithMapArguments { }; }; - const mapDispatchToProps = (dispatch: Dispatch, ownProps: GreetingProps) => { + const mapDispatchToProps = (dispatch: Dispatch, ownProps: GreetingProps) => { return { onClick: () => { dispatch({ type: 'GREETING', name: ownProps.name }); @@ -609,7 +609,7 @@ namespace TestTOwnPropsInference { state: string; } - class OwnPropsComponent extends React.Component> { + class OwnPropsComponent extends React.Component { render() { return
; } @@ -647,7 +647,7 @@ namespace TestTOwnPropsInference { state: string } - class AllPropsComponent extends React.Component> { + class AllPropsComponent extends React.Component { render() { return
; } @@ -691,7 +691,7 @@ namespace TestMergedPropsInference { return { state: 'string' }; } - function mapDispatchToProps(dispatch: Dispatch): DispatchProps { + function mapDispatchToProps(dispatch: Dispatch): DispatchProps { return { dispatch: 'string' }; } @@ -729,7 +729,7 @@ namespace Issue16652 { comments: ({ id: string } | undefined)[]; } - class CommentList extends React.Component> {} + class CommentList extends React.Component {} const mapStateToProps = (state: any, ownProps: PassedProps): GeneratedStateProps => { return { @@ -748,7 +748,7 @@ namespace Issue15463 { interface ISpinnerProps{ showGlobalSpinner: boolean; } - class SpinnerClass extends React.Component, undefined> { + class SpinnerClass extends React.Component { render() { return (
); } @@ -766,7 +766,7 @@ namespace RemoveInjectedAndPassOnRest { showGlobalSpinner: boolean; foo: string; } - class SpinnerClass extends React.Component, {}> { + class SpinnerClass extends React.Component { render() { return (
); } @@ -877,8 +877,8 @@ namespace TestCreateProvider { }; interface State { a: number }; - const store = createStore(() => ({ a: 1 })); - const myStore = createStore(() => ({ a: 2 })); + const store = createStore(() => ({ a: 1 })); + const myStore = createStore(() => ({ a: 2 })); interface AProps { a: number }; const A = (props: AProps) => (

A is {props.a}

);