mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-15 12:09:40 +08:00
Merge pull request #17196 from blakeembrey/explicit-infer
[react-redux] Explicitly enable inference with `connect()`
This commit is contained in:
8
types/react-redux/index.d.ts
vendored
8
types/react-redux/index.d.ts
vendored
@@ -20,7 +20,11 @@ export interface DispatchProp<S> {
|
||||
}
|
||||
|
||||
interface ComponentDecorator<TMergedProps, TOwnProps> {
|
||||
<T extends TOwnProps>(component: Component<T & TMergedProps>): ComponentClass<T>;
|
||||
(component: Component<TOwnProps & TMergedProps>): ComponentClass<TOwnProps>;
|
||||
}
|
||||
|
||||
interface ComponentDecoratorInfer<TMergedProps> {
|
||||
<T>(component: Component<T & TMergedProps>): ComponentClass<T>;
|
||||
}
|
||||
|
||||
interface ComponentMergeDecorator<TMergedProps, TOwnProps> {
|
||||
@@ -46,7 +50,7 @@ interface ComponentMergeDecorator<TMergedProps, TOwnProps> {
|
||||
* @param mergeProps
|
||||
* @param options
|
||||
*/
|
||||
export declare function connect(): ComponentDecorator<DispatchProp<any>, {}>;
|
||||
export declare function connect(): ComponentDecoratorInfer<DispatchProp<any>>;
|
||||
|
||||
export declare function connect<TStateProps, no_dispatch, TOwnProps>(
|
||||
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps>
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Component, ReactElement } from 'react';
|
||||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import { Store, Dispatch, bindActionCreators } from 'redux';
|
||||
import { connect, Provider, DispatchProp } from 'react-redux';
|
||||
import { connect, Provider, DispatchProp, MapStateToProps } from 'react-redux';
|
||||
import objectAssign = require('object-assign');
|
||||
|
||||
//
|
||||
@@ -375,6 +375,26 @@ namespace TestTOwnPropsInference {
|
||||
|
||||
// This should not compile, which is good.
|
||||
// React.createElement(ConnectedWithTypeHint, { anything: 'goes!' });
|
||||
|
||||
interface AllProps {
|
||||
own: string
|
||||
state: string
|
||||
}
|
||||
|
||||
class AllPropsComponent extends React.Component<AllProps & DispatchProp<any>, void> {
|
||||
render() {
|
||||
return <div/>;
|
||||
}
|
||||
}
|
||||
|
||||
type PickedOwnProps = Pick<AllProps, "own">
|
||||
type PickedStateProps = Pick<AllProps, "state">
|
||||
|
||||
const mapStateToPropsForPicked: MapStateToProps<PickedStateProps, PickedOwnProps> = (state: any): PickedStateProps => {
|
||||
return { state: "string" }
|
||||
}
|
||||
const ConnectedWithPickedOwnProps = connect(mapStateToPropsForPicked)(AllPropsComponent);
|
||||
<ConnectedWithPickedOwnProps own="blah" />
|
||||
}
|
||||
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/16021
|
||||
|
||||
Reference in New Issue
Block a user