Revert "[react-redux] Update type definitions for redux@4.0.0 (#25109)" (#25367)

This reverts commit 1efe02587a.
This commit is contained in:
ryym
2018-04-27 08:50:30 -07:00
committed by Wesley Wigham
parent c263542f44
commit 5ca461cbd3
3 changed files with 33 additions and 33 deletions
+9 -9
View File
@@ -26,14 +26,14 @@ type StatelessComponent<P> = React.StatelessComponent<P>;
type Component<P> = React.ComponentType<P>;
type ReactNode = React.ReactNode;
type Store<S> = Redux.Store<S>;
type Dispatch<A extends Redux.Action = Redux.AnyAction> = Redux.Dispatch<A>;
type Dispatch<S> = Redux.Dispatch<S>;
type ActionCreator<A> = Redux.ActionCreator<A>;
// Diff / Omit taken from https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-311923766
type Omit<T, K extends keyof T> = Pick<T, ({ [P in keyof T]: P } & { [P in K]: never } & { [x: string]: never, [x: number]: never })[keyof T]>;
export interface DispatchProp<A extends Redux.Action = Redux.AnyAction> {
dispatch?: Dispatch<A>;
export interface DispatchProp<S> {
dispatch?: Dispatch<S>;
}
interface AdvancedComponentDecorator<TProps, TOwnProps> {
@@ -75,11 +75,11 @@ export type InferableComponentEnhancer<TInjectedProps> =
* @param options
*/
export interface Connect {
(): InferableComponentEnhancer<DispatchProp>;
(): InferableComponentEnhancer<DispatchProp<any>>;
<TStateProps = {}, no_dispatch = {}, TOwnProps = {}, State = {}>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>
): InferableComponentEnhancerWithProps<TStateProps & DispatchProp & TOwnProps, TOwnProps>;
): InferableComponentEnhancerWithProps<TStateProps & DispatchProp<any> & TOwnProps, TOwnProps>;
<no_state = {}, TDispatchProps = {}, TOwnProps = {}>(
mapStateToProps: null | undefined,
@@ -120,7 +120,7 @@ export interface Connect {
mapDispatchToProps: null | undefined,
mergeProps: null | undefined,
options: Options<State, TStateProps, TOwnProps>
): InferableComponentEnhancerWithProps<DispatchProp & TStateProps, TOwnProps>;
): InferableComponentEnhancerWithProps<DispatchProp<any> & TStateProps, TOwnProps>;
<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}>(
mapStateToProps: null | undefined,
@@ -160,14 +160,14 @@ interface MapStateToPropsFactory<TStateProps, TOwnProps, State> {
type MapStateToPropsParam<TStateProps, TOwnProps, State> = MapStateToPropsFactory<TStateProps, TOwnProps, State> | MapStateToProps<TStateProps, TOwnProps, State> | null | undefined;
interface MapDispatchToPropsFunction<TDispatchProps, TOwnProps> {
(dispatch: Dispatch, ownProps: TOwnProps): TDispatchProps;
(dispatch: Dispatch<any>, ownProps: TOwnProps): TDispatchProps;
}
type MapDispatchToProps<TDispatchProps, TOwnProps> =
MapDispatchToPropsFunction<TDispatchProps, TOwnProps> | TDispatchProps;
interface MapDispatchToPropsFactory<TDispatchProps, TOwnProps> {
(dispatch: Dispatch, ownProps: TOwnProps): MapDispatchToProps<TDispatchProps, TOwnProps>;
(dispatch: Dispatch<any>, ownProps: TOwnProps): MapDispatchToProps<TDispatchProps, TOwnProps>;
}
type MapDispatchToPropsParam<TDispatchProps, TOwnProps> = MapDispatchToPropsFactory<TDispatchProps, TOwnProps> | MapDispatchToProps<TDispatchProps, TOwnProps>;
@@ -235,7 +235,7 @@ export declare function connectAdvanced<S, TProps, TOwnProps, TFactoryOptions =
* previous object when appropriate.
*/
export interface SelectorFactory<S, TProps, TOwnProps, TFactoryOptions> {
(dispatch: Dispatch, factoryOptions: TFactoryOptions): Selector<S, TProps, TOwnProps>
(dispatch: Dispatch<S>, factoryOptions: TFactoryOptions): Selector<S, TProps, TOwnProps>
}
export interface Selector<S, TProps, TOwnProps> {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"private": true,
"dependencies": {
"redux": "^4.0.0"
"redux": "^3.6.0"
}
}
+23 -23
View File
@@ -1,7 +1,7 @@
import { Component, ReactElement } from 'react';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Store, Dispatch, AnyAction, ActionCreator, createStore, bindActionCreators, ActionCreatorsMapObject } from 'redux';
import { Store, Dispatch, 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<any> }
class TestComponent extends Component<OwnProps> {}
@@ -42,7 +42,7 @@ namespace MapState {
namespace MapStateWithDispatchProp {
interface OwnProps { foo: string }
interface StateProps { bar: number, dispatch: Dispatch }
interface StateProps { bar: number, dispatch: Dispatch<any> }
class TestComponent extends Component<OwnProps & StateProps> {}
@@ -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<any> }
class TestComponent extends Component<OwnProps & StateProps & DispatchProps> {}
@@ -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<CounterState>) {
return {
onIncrement: () => dispatch(increment())
};
@@ -327,7 +327,7 @@ connect<ICounterStateProps, ICounterDispatchProps, {}, CounterState>(
// with higher order functions using parameters
connect<ICounterStateProps, ICounterDispatchProps, {}, CounterState>(
(initialState: CounterState, ownProps) => mapStateToProps,
(dispatch: Dispatch, ownProps) => mapDispatchToProps
(dispatch: Dispatch<CounterState>, ownProps) => mapDispatchToProps
)(Counter);
// only first argument
connect<ICounterStateProps, {}, {}, CounterState>(
@@ -415,7 +415,7 @@ ReactDOM.render(
// Inject just dispatch and don't listen to store
const AppWrap = (props: DispatchProp & { children?: React.ReactNode }) => <div />
const AppWrap = (props: DispatchProp<any> & { children?: React.ReactNode }) => <div />
const WrappedApp = connect()(AppWrap);
<WrappedApp />
@@ -446,7 +446,7 @@ connect(mapStateToProps2, actionCreators)(TodoApp);
// return { todos: state.todos };
//}
function mapDispatchToProps2(dispatch: Dispatch) {
function mapDispatchToProps2(dispatch: Dispatch<TodoState>) {
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<TodoState>) {
return bindActionCreators({ addTodo }, dispatch);
}
@@ -470,7 +470,7 @@ connect(mapStateToProps2, mapDispatchToProps3)(TodoApp);
// return { todos: state.todos };
//}
function mapDispatchToProps4(dispatch: Dispatch) {
function mapDispatchToProps4(dispatch: Dispatch<TodoState>) {
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<TodoState>) {
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<TodoState>) {
return bindActionCreators(objectAssign({}, todoActionCreators, counterActionCreators), dispatch);
}
@@ -541,7 +541,7 @@ interface TestState {
isLoaded: boolean;
state1: number;
}
class TestComponent extends Component<TestProp & DispatchProp, TestState> { }
class TestComponent extends Component<TestProp & DispatchProp<any>, TestState> { }
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<any>
name: string;
}
const HelloMessage: React.StatelessComponent<HelloMessageProps> = (props) => {
@@ -585,7 +585,7 @@ namespace TestStatelessFunctionWithMapArguments {
};
};
const mapDispatchToProps = (dispatch: Dispatch, ownProps: GreetingProps) => {
const mapDispatchToProps = (dispatch: Dispatch<any>, ownProps: GreetingProps) => {
return {
onClick: () => {
dispatch({ type: 'GREETING', name: ownProps.name });
@@ -609,7 +609,7 @@ namespace TestTOwnPropsInference {
state: string;
}
class OwnPropsComponent extends React.Component<StateProps & OwnProps & DispatchProp> {
class OwnPropsComponent extends React.Component<StateProps & OwnProps & DispatchProp<any>> {
render() {
return <div/>;
}
@@ -647,7 +647,7 @@ namespace TestTOwnPropsInference {
state: string
}
class AllPropsComponent extends React.Component<AllProps & DispatchProp> {
class AllPropsComponent extends React.Component<AllProps & DispatchProp<any>> {
render() {
return <div/>;
}
@@ -691,7 +691,7 @@ namespace TestMergedPropsInference {
return { state: 'string' };
}
function mapDispatchToProps(dispatch: Dispatch): DispatchProps {
function mapDispatchToProps(dispatch: Dispatch<any>): DispatchProps {
return { dispatch: 'string' };
}
@@ -729,7 +729,7 @@ namespace Issue16652 {
comments: ({ id: string } | undefined)[];
}
class CommentList extends React.Component<PassedProps & GeneratedStateProps & DispatchProp> {}
class CommentList extends React.Component<PassedProps & GeneratedStateProps & DispatchProp<any>> {}
const mapStateToProps = (state: any, ownProps: PassedProps): GeneratedStateProps => {
return {
@@ -748,7 +748,7 @@ namespace Issue15463 {
interface ISpinnerProps{
showGlobalSpinner: boolean;
}
class SpinnerClass extends React.Component<ISpinnerProps & DispatchProp, undefined> {
class SpinnerClass extends React.Component<ISpinnerProps & DispatchProp<any>, undefined> {
render() {
return (<div />);
}
@@ -766,7 +766,7 @@ namespace RemoveInjectedAndPassOnRest {
showGlobalSpinner: boolean;
foo: string;
}
class SpinnerClass extends React.Component<TProps & DispatchProp, {}> {
class SpinnerClass extends React.Component<TProps & DispatchProp<any>, {}> {
render() {
return (<div />);
}
@@ -877,8 +877,8 @@ namespace TestCreateProvider {
};
interface State { a: number };
const store = createStore<State, AnyAction, {}, {}>(() => ({ a: 1 }));
const myStore = createStore<State, AnyAction, {}, {}>(() => ({ a: 2 }));
const store = createStore<State>(() => ({ a: 1 }));
const myStore = createStore<State>(() => ({ a: 2 }));
interface AProps { a: number };
const A = (props: AProps) => (<h1>A is {props.a}</h1>);