mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 14:27:04 +00:00
Merge pull request #31799 from VincentLanglet/patchReactRedux
[react-redux] Improve Selector type to handle function with no OwnProps
This commit is contained in:
Vendored
+3
-1
@@ -352,7 +352,9 @@ export function connectAdvanced<S, TProps, TOwnProps, TFactoryOptions = {}>(
|
||||
export type SelectorFactory<S, TProps, TOwnProps, TFactoryOptions> =
|
||||
(dispatch: Dispatch<Action>, factoryOptions: TFactoryOptions) => Selector<S, TProps, TOwnProps>;
|
||||
|
||||
export type Selector<S, TProps, TOwnProps> = (state: S, ownProps: TOwnProps) => TProps;
|
||||
export type Selector<S, TProps, TOwnProps = null> = TOwnProps extends null | undefined
|
||||
? (state: S) => TProps
|
||||
: (state: S, ownProps: TOwnProps) => TProps;
|
||||
|
||||
export interface ConnectOptions {
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import { Store, Dispatch, AnyAction, ActionCreator, createStore, bindActionCreators, ActionCreatorsMapObject, Reducer } from 'redux';
|
||||
import { Connect, connect, Provider, DispatchProp, MapStateToProps, Options, ReactReduxContext, ReactReduxContextValue } from 'react-redux';
|
||||
import { Connect, connect, Provider, DispatchProp, MapStateToProps, Options, ReactReduxContext, ReactReduxContextValue, Selector } from 'react-redux';
|
||||
import objectAssign = require('object-assign');
|
||||
|
||||
//
|
||||
@@ -1192,3 +1192,18 @@ function TestProviderContext() {
|
||||
// Null is not a valid value for the context.
|
||||
<Provider store={store} context={null} />; // $ExpectError
|
||||
}
|
||||
|
||||
function TestSelector() {
|
||||
interface OwnProps { key?: string; }
|
||||
interface State { key: string; }
|
||||
|
||||
const simpleSelect: Selector<State, string> = (state: State) => state.key;
|
||||
const notSimpleSelect: Selector<State, string, OwnProps> = (state: State, ownProps: OwnProps) => ownProps.key || state.key;
|
||||
|
||||
const ownProps = {};
|
||||
const state = { key: 'value' };
|
||||
simpleSelect(state);
|
||||
notSimpleSelect(state, ownProps);
|
||||
simpleSelect(state, ownProps); // $ExpectError
|
||||
notSimpleSelect(state); // $ExpectError
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user