mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #8795 from seansfkelley/react-redux-remove-props
react-redux: remove props, add test for #8787
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
||||
Vendored
+8
-14
@@ -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>;
|
||||
}
|
||||
|
||||
@@ -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>,
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user