-
Notifications
You must be signed in to change notification settings - Fork 28
feat(react instantsearch widget): add connector and widget metadata #570
Conversation
type Connector<TProvided = {}, TExposed = {}> = (( | ||
stateless: React.FunctionComponent<ConnectorProvided<TProvided>> | ||
) => React.ComponentClass<TExposed>) & | ||
(<TProps extends Partial<ConnectorProvided<TProvided>>>( | ||
Composed: React.ComponentType<TProps> | ||
) => ConnectedComponentClass<TProps, ConnectorProvided<TProvided>, TExposed>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only way I could find to fix a TypeScript error during build:types
is to explicitly set the type (by copying it from @types/react-instantsearch-core) and assign it to the connector.
Here's the issue for reference:
$ tsc -p tsconfig.declaration.json
src/lib/connector.ts:19:14 - error TS2742: The inferred type of 'connectWidget' cannot be named without a reference to 'react-instantsearch-core/node_modules/@types/react'. This is likely not portable. A type annotation is necessary.
19 export const connectWidget = createConnector<ProvidedProps>({
~~~~~~~~~~~~~
type WidgetParams = { | ||
/** | ||
* Placeholder text for input element. | ||
*/ | ||
placeholder?: string; | ||
}; | ||
|
||
export const {{ pascalCaseName }}: ElementType<WidgetParams> = | ||
connect{{ pascalCaseName }}({{ pascalCaseName }}Component); | ||
export const {{ pascalCaseName }}: React.ElementType<WidgetParams> = connect{{ pascalCaseName }}( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from ElementType
to React.ElementType
fixes a TypeScript error during build:types
. I don't know why though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's odd that connector needs to be retyped, but no big deal
This PR adds support for
$$type
and$$widgetType
in the React InstantSearch Widget template. It also addresses some build issues.Ticket: FX-993
Result
$$type
and$$widgetType
(to{{ organization }}.{{ widgetName }}
by default)InstantSearch
fromreact-instantsearch-dom