mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 14:27:04 +00:00
Merge pull request #15929 from thasner/react-redux/connect
`react-redux` `ComponentDecorator` input accepts `TOwnProps`
This commit is contained in:
Vendored
+11
-10
@@ -1,6 +1,6 @@
|
||||
// Type definitions for react-redux 4.4.0
|
||||
// Project: https://github.com/rackt/react-redux
|
||||
// Definitions by: Qubo <https://github.com/tkqubo>, Sean Kelley <https://github.com/seansfkelley>
|
||||
// Definitions by: Qubo <https://github.com/tkqubo>, Sean Kelley <https://github.com/seansfkelley>, Thomas Hasner <https://github.com/thasner>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
@@ -9,13 +9,14 @@ import * as Redux from 'redux';
|
||||
|
||||
type ComponentClass<P> = React.ComponentClass<P>;
|
||||
type StatelessComponent<P> = React.StatelessComponent<P>;
|
||||
type Component<P> = ComponentClass<P> | StatelessComponent<P>;
|
||||
type ReactNode = React.ReactNode;
|
||||
type Store<S> = Redux.Store<S>;
|
||||
type Dispatch<S> = Redux.Dispatch<S>;
|
||||
type ActionCreator<A> = Redux.ActionCreator<A>;
|
||||
|
||||
interface ComponentDecorator<TOriginalProps, TOwnProps> {
|
||||
(component: ComponentClass<TOriginalProps> | StatelessComponent<TOriginalProps>): ComponentClass<TOwnProps>;
|
||||
interface ComponentDecorator<TStateProps, TDispatchProps, TOwnProps> {
|
||||
(component: Component<TStateProps & TDispatchProps & TOwnProps>): ComponentClass<TOwnProps>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,8 +24,8 @@ interface ComponentDecorator<TOriginalProps, TOwnProps> {
|
||||
*
|
||||
* Can't use the above decorator because it would default the type to {}
|
||||
*/
|
||||
export interface InferableComponentDecorator {
|
||||
<P, TComponentConstruct extends (ComponentClass<P> | StatelessComponent<P>)>(component: TComponentConstruct): TComponentConstruct;
|
||||
export interface InferableComponentDecorator<TOwnProps> {
|
||||
<T extends Component<TOwnProps>>(component: T): T;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,14 +47,14 @@ export interface InferableComponentDecorator {
|
||||
* @param mergeProps
|
||||
* @param options
|
||||
*/
|
||||
export declare function connect(): InferableComponentDecorator;
|
||||
export declare function connect<TOwnProps>(): InferableComponentDecorator<TOwnProps>;
|
||||
|
||||
export declare function connect<TStateProps, TDispatchProps, TOwnProps>(
|
||||
mapStateToProps?: MapStateToProps<TStateProps, TOwnProps> | MapStateToPropsFactory<TStateProps, TOwnProps>,
|
||||
mapDispatchToProps?: MapDispatchToProps<TDispatchProps, TOwnProps> | MapDispatchToPropsFactory<TDispatchProps, TOwnProps>,
|
||||
mergeProps?: MergeProps<TStateProps, TDispatchProps, TOwnProps>,
|
||||
options?: Options
|
||||
): ComponentDecorator<TStateProps & TDispatchProps, TOwnProps>;
|
||||
): ComponentDecorator<TStateProps, TDispatchProps, TOwnProps>;
|
||||
|
||||
interface MapStateToProps<TStateProps, TOwnProps> {
|
||||
(state: any, ownProps?: TOwnProps): TStateProps;
|
||||
@@ -92,9 +93,9 @@ interface Options {
|
||||
*/
|
||||
pure?: boolean;
|
||||
/**
|
||||
* If true, stores a ref to the wrapped component instance and makes it available via
|
||||
* getWrappedInstance() method. Defaults to false.
|
||||
*/
|
||||
* If true, stores a ref to the wrapped component instance and makes it available via
|
||||
* getWrappedInstance() method. Defaults to false.
|
||||
*/
|
||||
withRef?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -343,7 +343,7 @@ namespace TestTOwnPropsInference {
|
||||
state: string;
|
||||
}
|
||||
|
||||
class OwnPropsComponent extends React.Component<OwnProps & StateProps, {}> {
|
||||
class OwnPropsComponent extends React.Component<OwnProps & StateProps, void> {
|
||||
render() {
|
||||
return <div/>;
|
||||
}
|
||||
@@ -359,7 +359,7 @@ namespace TestTOwnPropsInference {
|
||||
|
||||
const ConnectedWithoutOwnProps = connect(mapStateToPropsWithoutOwnProps)(OwnPropsComponent);
|
||||
const ConnectedWithOwnProps = connect(mapStateToPropsWithOwnProps)(OwnPropsComponent);
|
||||
const ConnectedWithTypeHint = connect<StateProps, {}, OwnProps>(mapStateToPropsWithoutOwnProps)(OwnPropsComponent);
|
||||
const ConnectedWithTypeHint = connect<StateProps, void, OwnProps>(mapStateToPropsWithoutOwnProps)(OwnPropsComponent);
|
||||
|
||||
// This compiles, which is bad.
|
||||
React.createElement(ConnectedWithoutOwnProps, { anything: 'goes!' });
|
||||
|
||||
Reference in New Issue
Block a user