Skip to content

Commit

Permalink
[react-redux] Update type definitions for redux@4.0.0 (DefinitelyType…
Browse files Browse the repository at this point in the history
  • Loading branch information
ryym authored and weswigham committed Apr 25, 2018
1 parent 4ed4461 commit 1efe025
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
18 changes: 9 additions & 9 deletions types/react-redux/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ type StatelessComponent<P> = React.StatelessComponent<P>;
type Component<P> = React.ComponentType<P>;
type ReactNode = React.ReactNode;
type Store<S> = Redux.Store<S>;
type Dispatch<S> = Redux.Dispatch<S>;
type Dispatch<A extends Redux.Action = Redux.AnyAction> = Redux.Dispatch<A>;
type ActionCreator<A> = Redux.ActionCreator<A>;

// Diff / Omit taken from https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-311923766
type Diff<T extends string, U extends string> = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;

export interface DispatchProp<S> {
dispatch?: Dispatch<S>;
export interface DispatchProp<A extends Redux.Action = Redux.AnyAction> {
dispatch?: Dispatch<A>;
}

interface AdvancedComponentDecorator<TProps, TOwnProps> {
Expand Down Expand Up @@ -76,11 +76,11 @@ export type InferableComponentEnhancer<TInjectedProps> =
* @param options
*/
export interface Connect {
(): InferableComponentEnhancer<DispatchProp<any>>;
(): InferableComponentEnhancer<DispatchProp>;

<TStateProps = {}, no_dispatch = {}, TOwnProps = {}, State = {}>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>
): InferableComponentEnhancerWithProps<TStateProps & DispatchProp<any> & TOwnProps, TOwnProps>;
): InferableComponentEnhancerWithProps<TStateProps & DispatchProp & TOwnProps, TOwnProps>;

<no_state = {}, TDispatchProps = {}, TOwnProps = {}>(
mapStateToProps: null | undefined,
Expand Down Expand Up @@ -121,7 +121,7 @@ export interface Connect {
mapDispatchToProps: null | undefined,
mergeProps: null | undefined,
options: Options<State, TStateProps, TOwnProps>
): InferableComponentEnhancerWithProps<DispatchProp<any> & TStateProps, TOwnProps>;
): InferableComponentEnhancerWithProps<DispatchProp & TStateProps, TOwnProps>;

<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}>(
mapStateToProps: null | undefined,
Expand Down Expand Up @@ -161,14 +161,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<any>, ownProps: TOwnProps): TDispatchProps;
(dispatch: Dispatch, ownProps: TOwnProps): TDispatchProps;
}

type MapDispatchToProps<TDispatchProps, TOwnProps> =
MapDispatchToPropsFunction<TDispatchProps, TOwnProps> | TDispatchProps;

interface MapDispatchToPropsFactory<TDispatchProps, TOwnProps> {
(dispatch: Dispatch<any>, ownProps: TOwnProps): MapDispatchToProps<TDispatchProps, TOwnProps>;
(dispatch: Dispatch, ownProps: TOwnProps): MapDispatchToProps<TDispatchProps, TOwnProps>;
}

type MapDispatchToPropsParam<TDispatchProps, TOwnProps> = MapDispatchToPropsFactory<TDispatchProps, TOwnProps> | MapDispatchToProps<TDispatchProps, TOwnProps>;
Expand Down Expand Up @@ -236,7 +236,7 @@ export declare function connectAdvanced<S, TProps, TOwnProps, TFactoryOptions =
* previous object when appropriate.
*/
export interface SelectorFactory<S, TProps, TOwnProps, TFactoryOptions> {
(dispatch: Dispatch<S>, factoryOptions: TFactoryOptions): Selector<S, TProps, TOwnProps>
(dispatch: Dispatch, factoryOptions: TFactoryOptions): Selector<S, TProps, TOwnProps>
}

export interface Selector<S, TProps, TOwnProps> {
Expand Down
2 changes: 1 addition & 1 deletion types/react-redux/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"dependencies": {
"redux": "^3.6.0"
"redux": "^4.0.0"
}
}
46 changes: 23 additions & 23 deletions types/react-redux/react-redux-tests.tsx
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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<any> }
interface OwnProps { foo: string, dispatch: Dispatch }

class TestComponent extends Component<OwnProps> {}

Expand Down Expand Up @@ -42,7 +42,7 @@ namespace MapState {

namespace MapStateWithDispatchProp {
interface OwnProps { foo: string }
interface StateProps { bar: number, dispatch: Dispatch<any> }
interface StateProps { bar: number, dispatch: Dispatch }

class TestComponent extends Component<OwnProps & StateProps> {}

Expand Down Expand Up @@ -250,7 +250,7 @@ namespace MapStateAndOptions {
interface State { state: string; }
interface OwnProps { foo: string }
interface StateProps { bar: number }
interface DispatchProps { dispatch: Dispatch<any> }
interface DispatchProps { dispatch: Dispatch }

class TestComponent extends Component<OwnProps & StateProps & DispatchProps> {}

Expand Down Expand Up @@ -295,7 +295,7 @@ function mapStateToProps(state: CounterState) {
}

// Which action creators does it want to receive by props?
function mapDispatchToProps(dispatch: Dispatch<CounterState>) {
function mapDispatchToProps(dispatch: Dispatch) {
return {
onIncrement: () => dispatch(increment())
};
Expand Down Expand Up @@ -327,7 +327,7 @@ connect<ICounterStateProps, ICounterDispatchProps, {}, CounterState>(
// with higher order functions using parameters
connect<ICounterStateProps, ICounterDispatchProps, {}, CounterState>(
(initialState: CounterState, ownProps) => mapStateToProps,
(dispatch: Dispatch<CounterState>, ownProps) => mapDispatchToProps
(dispatch: Dispatch, ownProps) => mapDispatchToProps
)(Counter);
// only first argument
connect<ICounterStateProps, {}, {}, CounterState>(
Expand Down Expand Up @@ -415,7 +415,7 @@ ReactDOM.render(

// Inject just dispatch and don't listen to store

const AppWrap = (props: DispatchProp<any> & { children?: React.ReactNode }) => <div />
const AppWrap = (props: DispatchProp & { children?: React.ReactNode }) => <div />
const WrappedApp = connect()(AppWrap);

<WrappedApp />
Expand Down Expand Up @@ -446,7 +446,7 @@ connect(mapStateToProps2, actionCreators)(TodoApp);
// return { todos: state.todos };
//}

function mapDispatchToProps2(dispatch: Dispatch<TodoState>) {
function mapDispatchToProps2(dispatch: Dispatch) {
return { actions: bindActionCreators(actionCreators, dispatch) };
}

Expand All @@ -458,7 +458,7 @@ connect(mapStateToProps2, mapDispatchToProps2)(TodoApp);
// return { todos: state.todos };
//}

function mapDispatchToProps3(dispatch: Dispatch<TodoState>) {
function mapDispatchToProps3(dispatch: Dispatch) {
return bindActionCreators({ addTodo }, dispatch);
}

Expand All @@ -470,7 +470,7 @@ connect(mapStateToProps2, mapDispatchToProps3)(TodoApp);
// return { todos: state.todos };
//}

function mapDispatchToProps4(dispatch: Dispatch<TodoState>) {
function mapDispatchToProps4(dispatch: Dispatch) {
return {
todoActions: bindActionCreators(todoActionCreators, dispatch),
counterActions: bindActionCreators(counterActionCreators, dispatch)
Expand All @@ -485,7 +485,7 @@ connect(mapStateToProps2, mapDispatchToProps4)(TodoApp);
// return { todos: state.todos };
//}

function mapDispatchToProps5(dispatch: Dispatch<TodoState>) {
function mapDispatchToProps5(dispatch: Dispatch) {
return {
actions: bindActionCreators(objectAssign({}, todoActionCreators, counterActionCreators), dispatch)
};
Expand All @@ -499,7 +499,7 @@ connect(mapStateToProps2, mapDispatchToProps5)(TodoApp);
// return { todos: state.todos };
//}

function mapDispatchToProps6(dispatch: Dispatch<TodoState>) {
function mapDispatchToProps6(dispatch: Dispatch) {
return bindActionCreators(objectAssign({}, todoActionCreators, counterActionCreators), dispatch);
}

Expand Down Expand Up @@ -541,7 +541,7 @@ interface TestState {
isLoaded: boolean;
state1: number;
}
class TestComponent extends Component<TestProp & DispatchProp<any>, TestState> { }
class TestComponent extends Component<TestProp & DispatchProp, TestState> { }
const WrappedTestComponent = connect()(TestComponent);

// return value of the connect()(TestComponent) is of the type TestComponent
Expand All @@ -559,7 +559,7 @@ class NonComponent {}

// stateless functions
interface HelloMessageProps {
dispatch: Dispatch<any>
dispatch: Dispatch
name: string;
}
const HelloMessage: React.StatelessComponent<HelloMessageProps> = (props) => {
Expand All @@ -585,7 +585,7 @@ namespace TestStatelessFunctionWithMapArguments {
};
};

const mapDispatchToProps = (dispatch: Dispatch<any>, ownProps: GreetingProps) => {
const mapDispatchToProps = (dispatch: Dispatch, ownProps: GreetingProps) => {
return {
onClick: () => {
dispatch({ type: 'GREETING', name: ownProps.name });
Expand All @@ -609,7 +609,7 @@ namespace TestTOwnPropsInference {
state: string;
}

class OwnPropsComponent extends React.Component<StateProps & OwnProps & DispatchProp<any>> {
class OwnPropsComponent extends React.Component<StateProps & OwnProps & DispatchProp> {
render() {
return <div/>;
}
Expand Down Expand Up @@ -647,7 +647,7 @@ namespace TestTOwnPropsInference {
state: string
}

class AllPropsComponent extends React.Component<AllProps & DispatchProp<any>> {
class AllPropsComponent extends React.Component<AllProps & DispatchProp> {
render() {
return <div/>;
}
Expand Down Expand Up @@ -691,7 +691,7 @@ namespace TestMergedPropsInference {
return { state: 'string' };
}

function mapDispatchToProps(dispatch: Dispatch<any>): DispatchProps {
function mapDispatchToProps(dispatch: Dispatch): DispatchProps {
return { dispatch: 'string' };
}

Expand Down Expand Up @@ -729,7 +729,7 @@ namespace Issue16652 {
comments: ({ id: string } | undefined)[];
}

class CommentList extends React.Component<PassedProps & GeneratedStateProps & DispatchProp<any>> {}
class CommentList extends React.Component<PassedProps & GeneratedStateProps & DispatchProp> {}

const mapStateToProps = (state: any, ownProps: PassedProps): GeneratedStateProps => {
return {
Expand All @@ -748,7 +748,7 @@ namespace Issue15463 {
interface ISpinnerProps{
showGlobalSpinner: boolean;
}
class SpinnerClass extends React.Component<ISpinnerProps & DispatchProp<any>, undefined> {
class SpinnerClass extends React.Component<ISpinnerProps & DispatchProp, undefined> {
render() {
return (<div />);
}
Expand All @@ -766,7 +766,7 @@ namespace RemoveInjectedAndPassOnRest {
showGlobalSpinner: boolean;
foo: string;
}
class SpinnerClass extends React.Component<TProps & DispatchProp<any>, {}> {
class SpinnerClass extends React.Component<TProps & DispatchProp, {}> {
render() {
return (<div />);
}
Expand Down Expand Up @@ -877,8 +877,8 @@ namespace TestCreateProvider {
};

interface State { a: number };
const store = createStore<State>(() => ({ a: 1 }));
const myStore = createStore<State>(() => ({ a: 2 }));
const store = createStore<State, AnyAction, {}, {}>(() => ({ a: 1 }));
const myStore = createStore<State, AnyAction, {}, {}>(() => ({ a: 2 }));

interface AProps { a: number };
const A = (props: AProps) => (<h1>A is {props.a}</h1>);
Expand Down

0 comments on commit 1efe025

Please sign in to comment.