mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 15:27:05 +00:00
Fix InferableComponentEnhancerWithProps type inference for StatelessComponent (#27781)
* Fix InferableComponentEnhancerWithProps type inference for StatelessComponent The inferred component should require the difference of props supplied by connect and props needed by the component to be passed during render. * Remove ambigous bidirectional type inference
This commit is contained in:
committed by
Sheetal Nandi
parent
6f8d56fbbf
commit
da8f444b22
Vendored
-3
@@ -73,9 +73,6 @@ type Shared<
|
||||
// Will not pass through the injected props if they are passed in during
|
||||
// render. Also adds new prop requirements from TNeedsProps.
|
||||
export interface InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> {
|
||||
(
|
||||
component: StatelessComponent<TInjectedProps>
|
||||
): ComponentClass<TNeedsProps> & {WrappedComponent: StatelessComponent<TInjectedProps>}
|
||||
<P extends Shared<TInjectedProps, P>>(
|
||||
component: ComponentType<P>
|
||||
): ComponentClass<Omit<P, keyof Shared<TInjectedProps, P>> & TNeedsProps> & {WrappedComponent: ComponentType<P>}
|
||||
|
||||
@@ -832,7 +832,12 @@ namespace TestDispatchToPropsAsObject {
|
||||
<Header />
|
||||
}
|
||||
|
||||
namespace TestInferredFunctionalComponent {
|
||||
namespace TestInferredFunctionalComponentWithExplicitOwnProps {
|
||||
type Props = {
|
||||
title: string,
|
||||
extraText: string,
|
||||
onClick: () => void,
|
||||
};
|
||||
|
||||
const Header = connect(
|
||||
(
|
||||
@@ -845,7 +850,30 @@ namespace TestInferredFunctionalComponent {
|
||||
(dispatch) => ({
|
||||
onClick: () => dispatch({ type: 'test' })
|
||||
})
|
||||
)(({ title, extraText, onClick }) => {
|
||||
)(({ title, extraText, onClick }: Props) => {
|
||||
return <h1 onClick={onClick}>{title} {extraText}</h1>;
|
||||
});
|
||||
<Header extraText='text'/>
|
||||
}
|
||||
|
||||
namespace TestInferredFunctionalComponentWithImplicitOwnProps {
|
||||
|
||||
type Props = {
|
||||
title: string,
|
||||
extraText: string,
|
||||
onClick: () => void,
|
||||
};
|
||||
|
||||
const Header = connect(
|
||||
(
|
||||
{ app: { title }}: { app: { title: string }},
|
||||
) => ({
|
||||
title,
|
||||
}),
|
||||
(dispatch) => ({
|
||||
onClick: () => dispatch({ type: 'test' })
|
||||
})
|
||||
)(({ title, extraText, onClick }: Props) => {
|
||||
return <h1 onClick={onClick}>{title} {extraText}</h1>;
|
||||
});
|
||||
<Header extraText='text'/>
|
||||
@@ -1126,4 +1154,4 @@ namespace TestFailsMoreSpecificInjectedProps {
|
||||
// Since it is possible the injected props could fail to satisfy the decoration props,
|
||||
// the following line should fail to compile.
|
||||
connect(mapStateToProps, mapDispatchToProps)(Component) // $ExpectError
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user