mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 23:10:29 +00:00
Fix type inference for connectStateResults
This commit is contained in:
+4
-4
@@ -511,10 +511,10 @@ export interface StateResultsProvided<TDoc = BasicDoc> {
|
||||
*
|
||||
* https://community.algolia.com/react-instantsearch/connectors/connectStateResults.html
|
||||
*/
|
||||
export function connectStateResults<TDoc = BasicDoc>(
|
||||
stateless: React.StatelessComponent<StateResultsProvided<TDoc>>): React.ComponentClass;
|
||||
export function connectStateResults<TProps extends Partial<StateResultsProvided<TDoc>>, TDoc = BasicDoc>(
|
||||
ctor: React.ComponentType<TProps>): ConnectedComponentClass<TProps, StateResultsProvided<TDoc>>;
|
||||
export function connectStateResults(
|
||||
stateless: React.StatelessComponent<StateResultsProvided>): React.ComponentClass;
|
||||
export function connectStateResults<TProps extends Partial<StateResultsProvided<any>>>(
|
||||
ctor: React.ComponentType<TProps>): ConnectedComponentClass<TProps, StateResultsProvided>;
|
||||
|
||||
interface StatsProvided {
|
||||
nbHits: number;
|
||||
|
||||
@@ -21,7 +21,8 @@ import {
|
||||
Hit,
|
||||
TranslatableProvided,
|
||||
translatable,
|
||||
ConnectorProvided
|
||||
ConnectorProvided,
|
||||
StateResultsProvided
|
||||
} from 'react-instantsearch-core';
|
||||
|
||||
() => {
|
||||
@@ -209,18 +210,35 @@ import {
|
||||
};
|
||||
|
||||
() => {
|
||||
interface MyDoc {
|
||||
field1: string;
|
||||
field2: number;
|
||||
field3: { compound: string };
|
||||
}
|
||||
|
||||
interface StateResultsProps {
|
||||
searchResults: SearchResults<{
|
||||
field1: string
|
||||
field2: number
|
||||
field3: { compound: string }
|
||||
}>;
|
||||
searchResults: SearchResults<MyDoc>;
|
||||
// partial of StateResultsProvided
|
||||
|
||||
additionalProp: string;
|
||||
}
|
||||
|
||||
const Stateless = ({ additionalProp, searchResults }: StateResultsProps) =>
|
||||
const Stateless = connectStateResults(
|
||||
({
|
||||
searchResults,
|
||||
additionalProp, // $ExpectError
|
||||
}) => (<div>
|
||||
<h1>{additionalProp}</h1>
|
||||
{searchResults.hits.map((h) => {
|
||||
return <span>{h._highlightResult.field1!.value}</span>;
|
||||
})}
|
||||
</div>)
|
||||
);
|
||||
|
||||
<Stateless />;
|
||||
<Stateless additionalProp='test' />; // $ExpectError
|
||||
|
||||
const StatelessWithType = ({ additionalProp, searchResults }: StateResultsProps) =>
|
||||
<div>
|
||||
<h1>{additionalProp}</h1>
|
||||
{searchResults.hits.map((h) => {
|
||||
@@ -229,11 +247,11 @@ import {
|
||||
return <span>{compound}</span>;
|
||||
})}
|
||||
</div>;
|
||||
const ComposedStateless = connectStateResults(Stateless);
|
||||
const ComposedStatelessWithType = connectStateResults(StatelessWithType);
|
||||
|
||||
<ComposedStateless />; // $ExpectError
|
||||
<ComposedStatelessWithType />; // $ExpectError
|
||||
|
||||
<ComposedStateless additionalProp='test' />;
|
||||
<ComposedStatelessWithType additionalProp='test' />;
|
||||
|
||||
class MyComponent extends React.Component<StateResultsProps> {
|
||||
render() {
|
||||
|
||||
Reference in New Issue
Block a user