Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#8795 from seansfkelley/react-redux…
Browse files Browse the repository at this point in the history
…-remove-props

react-redux: remove props, add test for DefinitelyTyped#8787
  • Loading branch information
vvakame committed Apr 5, 2016
2 parents 9d7816b + 8a7d208 commit cb5ace8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
44 changes: 44 additions & 0 deletions react-redux/react-redux-tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,47 @@ function HelloMessage(props: HelloMessageProps) {
let ConnectedHelloMessage = connect()(HelloMessage);
ReactDOM.render(<HelloMessage name="Sebastian" />, document.getElementById('content'));
ReactDOM.render(<ConnectedHelloMessage name="Sebastian" />, document.getElementById('content'));

// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/8787
namespace TestTOwnPropsInference {
interface OwnProps {
own: string;
}

interface StateProps {
state: string;
}

class OwnPropsComponent extends React.Component<OwnProps & StateProps, {}> {
render() {
return <div/>;
}
}

function mapStateToPropsWithoutOwnProps(state: any): StateProps {
return { state: 'string' };
}

function mapStateToPropsWithOwnProps(state: any, ownProps: OwnProps): StateProps {
return { state: 'string' };
}

const ConnectedWithoutOwnProps = connect(mapStateToPropsWithoutOwnProps)(OwnPropsComponent);
const ConnectedWithOwnProps = connect(mapStateToPropsWithOwnProps)(OwnPropsComponent);
const ConnectedWithTypeHint = connect<StateProps, {}, OwnProps>(mapStateToPropsWithoutOwnProps)(OwnPropsComponent);

// This compiles, which is bad.
React.createElement(ConnectedWithoutOwnProps, { anything: 'goes!' });

// This compiles, as expected.
React.createElement(ConnectedWithOwnProps, { own: 'string' });

// This should not compile, which is good.
// React.createElement(ConnectedWithOwnProps, { missingOwn: true });

// This compiles, as expected.
React.createElement(ConnectedWithTypeHint, { own: 'string' });

// This should not compile, which is good.
// React.createElement(ConnectedWithTypeHint, { missingOwn: true });
}
22 changes: 8 additions & 14 deletions react-redux/react-redux.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Type definitions for react-redux 4.4.0
// Project: https://github.com/rackt/react-redux
// Definitions by: Qubo <https://github.com/tkqubo>
// Definitions by: Qubo <https://github.com/tkqubo>, Sean Kelley <https://github.com/seansfkelley>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/// <reference path="../react/react.d.ts" />
/// <reference path="../redux/redux.d.ts" />

declare module "react-redux" {
import { ComponentClass, Component, StatelessComponent, Props, ReactNode } from 'react';
import { ComponentClass, Component, StatelessComponent, ReactNode } from 'react';
import { Store, Dispatch, ActionCreator } from 'redux';

interface ComponentDecorator<TOriginalProps extends Props<any>, TOwnProps extends Props<any>> {
interface ComponentDecorator<TOriginalProps, TOwnProps> {
(component: ComponentClass<TOriginalProps>): ComponentClass<TOwnProps>;
}

Expand Down Expand Up @@ -43,19 +43,13 @@ declare module "react-redux" {
* @param options
*/
export function connect(): InferableComponentDecorator;
export function connect<
TStateProps extends Props<any>,
TDispatchProps extends Props<any>,
TOwnProps extends Props<any>
>(

export function connect<TStateProps, TDispatchProps, TOwnProps>(
mapStateToProps: MapStateToProps<TStateProps, TOwnProps>,
mapDispatchToProps?: MapDispatchToPropsFunction<TDispatchProps, TOwnProps>|MapDispatchToPropsObject
): ComponentDecorator<TStateProps & TDispatchProps, TOwnProps>;
export function connect<
TStateProps extends Props<any>,
TDispatchProps extends Props<any>,
TOwnProps extends Props<any>
>(

export function connect<TStateProps, TDispatchProps, TOwnProps>(
mapStateToProps: MapStateToProps<TStateProps, TOwnProps>,
mapDispatchToProps: MapDispatchToPropsFunction<TDispatchProps, TOwnProps>|MapDispatchToPropsObject,
mergeProps: MergeProps<TStateProps, TDispatchProps, TOwnProps>,
Expand Down Expand Up @@ -89,7 +83,7 @@ declare module "react-redux" {
pure: boolean;
}

export interface ProviderProps extends Props<Provider> {
export interface ProviderProps {
/**
* The single Redux store in your application.
*/
Expand Down

0 comments on commit cb5ace8

Please sign in to comment.