Skip to content

Commit

Permalink
fix type
Browse files Browse the repository at this point in the history
  • Loading branch information
eunjae-lee committed Sep 30, 2020
1 parent 91425cf commit 54e31fc
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 57 deletions.
14 changes: 4 additions & 10 deletions src/connectors/autocomplete/connectAutocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
noop,
warning,
} from '../../lib/utils';
import { Hits, Connector, AutocompleteWidgetRenderState } from '../../types';
import { Hits, Connector } from '../../types';

const withUsage = createDocumentationMessageGenerator({
name: 'autocomplete',
Expand Down Expand Up @@ -110,9 +110,7 @@ search.addWidgets([

renderFn(
{
...this.getWidgetRenderState!<AutocompleteWidgetRenderState>(
initOptions
),
...this.getWidgetRenderState!(initOptions),
instantSearchInstance,
},
true
Expand All @@ -124,9 +122,7 @@ search.addWidgets([

renderFn(
{
...this.getWidgetRenderState!<AutocompleteWidgetRenderState>(
renderOptions
),
...this.getWidgetRenderState!(renderOptions),
instantSearchInstance,
},
false
Expand All @@ -136,9 +132,7 @@ search.addWidgets([
getRenderState(renderState, renderOptions) {
return {
...renderState,
autocomplete: this.getWidgetRenderState!<
AutocompleteWidgetRenderState
>(renderOptions),
autocomplete: this.getWidgetRenderState!(renderOptions),
};
},

Expand Down
114 changes: 67 additions & 47 deletions src/types/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,37 +229,6 @@ type WidgetRenderState<
* have at least a `render` or a `init` function.
*/
export type Widget = {
$$type?:
| 'ais.autocomplete'
| 'ais.breadcrumb'
| 'ais.clearRefinements'
| 'ais.configure'
| 'ais.configureRelatedItems'
| 'ais.currentRefinements'
| 'ais.geoSearch'
| 'ais.hierarchicalMenu'
| 'ais.hits'
| 'ais.hitsPerPage'
| 'ais.index'
| 'ais.infiniteHits'
| 'ais.menu'
| 'ais.numericMenu'
| 'ais.pagination'
| 'ais.places'
| 'ais.poweredBy'
| 'ais.queryRules'
| 'ais.queryRuleCustomData'
| 'ais.queryRuleContext'
| 'ais.range'
| 'ais.rangeInput'
| 'ais.rangeSlider'
| 'ais.ratingMenu'
| 'ais.refinementList'
| 'ais.searchBox'
| 'ais.sortBy'
| 'ais.stats'
| 'ais.toggleRefinement'
| 'ais.voiceSearch';
/**
* Called once before the first search
*/
Expand All @@ -281,21 +250,6 @@ export type Widget = {
renderState: IndexRenderState,
renderOptions: InitOptions | RenderOptions
): IndexRenderState;
/**
* Returns the render state of the current widget to pass to the render function.
*/
getWidgetRenderState?<
TWidgetRenderState =
| SearchBoxWidgetRenderState
| AutocompleteWidgetRenderState
| BreadcrumbWidgetRenderState
| ClearRefinementsWidgetRenderState
| ConfigureWidgetRenderState
| CurrentRefinementsWidgetRenderState
| HierarchicalMenuWidgetRenderState
>(
renderOptions: InitOptions | RenderOptions
): TWidgetRenderState;
/**
* This function is required for a widget to be taken in account for routing.
* It will derive a uiState for this widget based on the existing uiState and
Expand Down Expand Up @@ -330,7 +284,73 @@ export type Widget = {
state: SearchParameters,
widgetSearchParametersOptions: WidgetSearchParametersOptions
): SearchParameters;
};
} & (
| {
$$type: 'ais.searchBox';
getWidgetRenderState?: (
renderOptions: InitOptions | RenderOptions
) => SearchBoxWidgetRenderState;
}
| {
$$type: 'ais.autocomplete';
getWidgetRenderState?: (
renderOptions: InitOptions | RenderOptions
) => AutocompleteWidgetRenderState;
}
| {
$$type: 'ais.breadcrumb';
getWidgetRenderState?: (
renderOptions: InitOptions | RenderOptions
) => BreadcrumbWidgetRenderState;
}
| {
$$type: 'ais.clearRefinements';
getWidgetRenderState?: (
renderOptions: InitOptions | RenderOptions
) => ClearRefinementsWidgetRenderState;
}
| {
$$type: 'ais.configure';
getWidgetRenderState?: (
renderOptions: InitOptions | RenderOptions
) => ConfigureWidgetRenderState;
}
| {
$$type: 'ais.currentRefinements';
getWidgetRenderState?: (
renderOptions: InitOptions | RenderOptions
) => CurrentRefinementsWidgetRenderState;
}
| {
$$type: 'ais.hierarchicalMenu';
getWidgetRenderState?: (
renderOptions: InitOptions | RenderOptions
) => HierarchicalMenuWidgetRenderState;
}
| { $$type: 'ais.configureRelatedItems' }
| { $$type: 'ais.geoSearch' }
| { $$type: 'ais.hits' }
| { $$type: 'ais.hitsPerPage' }
| { $$type: 'ais.index' }
| { $$type: 'ais.infiniteHits' }
| { $$type: 'ais.menu' }
| { $$type: 'ais.numericMenu' }
| { $$type: 'ais.pagination' }
| { $$type: 'ais.places' }
| { $$type: 'ais.poweredBy' }
| { $$type: 'ais.queryRules' }
| { $$type: 'ais.queryRuleCustomData' }
| { $$type: 'ais.queryRuleContext' }
| { $$type: 'ais.range' }
| { $$type: 'ais.rangeInput' }
| { $$type: 'ais.rangeSlider' }
| { $$type: 'ais.ratingMenu' }
| { $$type: 'ais.refinementList' }
| { $$type: 'ais.sortBy' }
| { $$type: 'ais.stats' }
| { $$type: 'ais.toggleRefinement' }
| { $$type: 'ais.voiceSearch' }
);

/**
* The function that creates a new widget.
Expand Down

0 comments on commit 54e31fc

Please sign in to comment.