From dcbbd8804b4b6471d24820b42826b57388974c27 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Wed, 18 Aug 2021 11:07:07 +0200 Subject: [PATCH] fix(types): export all types as "type" to avoid exporting in .js (#4837) * fix(types): export all types as "type" to avoid exporting in .js This issue is caused by `export * from './types'` added in #4834, which causes everything in /types to be exposed, but unfortunately because `export from` in the InstantSearch file mixed a type and a value, and thus exported it. This is done by enabling [consistent-type-imports](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-imports.md) in eslint to make sure it's correct in all cases references: - code that throws: https://unpkg.com/browse/instantsearch.js@4.27.1/es/types/instantsearch.js - vite reproduction: https://github.com/eunjae-lee/vue-instantsearch-with-vue3-and-vite * fix ts * chore(ts): also enable `isolatedModules` this catches when you export something that's a type as a regular export, further avoiding the issue --- .eslintrc.js | 1 + examples/e-commerce/src/routing.ts | 6 +-- .../jest/matchers/__tests__/toWarnDev-test.ts | 4 ++ src/components/Answers/Answers.tsx | 4 +- .../Answers/__tests__/Answers-test.tsx | 3 +- src/components/Breadcrumb/Breadcrumb.tsx | 8 +-- .../Breadcrumb/__tests__/Breadcrumb-test.tsx | 3 +- .../ClearRefinements/ClearRefinements.tsx | 8 +-- .../CurrentRefinements/CurrentRefinements.tsx | 6 +-- .../GeoSearchControls/GeoSearchButton.tsx | 3 +- .../GeoSearchControls/GeoSearchControls.tsx | 6 +-- .../GeoSearchControls/GeoSearchToggle.tsx | 3 +- src/components/Hits/Hits.tsx | 10 ++-- src/components/Hits/__tests__/Hits-test.tsx | 3 +- src/components/InfiniteHits/InfiniteHits.tsx | 8 +-- .../__tests__/InfiniteHits-test.tsx | 2 +- src/components/MenuSelect/MenuSelect.tsx | 6 +-- src/components/Pagination/Pagination.tsx | 4 +- .../Pagination/__tests__/Pagination-test.tsx | 3 +- src/components/Panel/Panel.tsx | 7 ++- src/components/Panel/__tests__/Panel-test.tsx | 3 +- src/components/PoweredBy/PoweredBy.tsx | 4 +- .../QueryRuleCustomData.tsx | 4 +- src/components/RangeInput/RangeInput.tsx | 9 ++-- .../RangeInput/__tests__/RangeInput-test.tsx | 3 +- .../RefinementList/RefinementList.tsx | 18 ++++--- .../RefinementList/RefinementListItem.tsx | 3 +- .../__tests__/RefinementList-test.tsx | 5 +- .../__tests__/RefinementListItem-test.tsx | 5 +- src/components/RelevantSort/RelevantSort.tsx | 4 +- .../__tests__/RelevantSort-test.tsx | 3 +- src/components/SearchBox/SearchBox.tsx | 4 +- src/components/Slider/Pit.tsx | 2 +- src/components/Slider/Rheostat.tsx | 17 +++--- src/components/Slider/Slider.tsx | 9 ++-- .../Slider/__tests__/Slider-test.tsx | 3 +- src/components/Stats/Stats.tsx | 7 ++- src/components/Template/Template.tsx | 7 +-- .../ToggleRefinement/ToggleRefinement.tsx | 8 +-- src/components/VoiceSearch/VoiceSearch.tsx | 6 +-- .../__tests__/VoiceSearch-test.tsx | 3 +- src/connectors/answers/connectAnswers.ts | 4 +- .../__tests__/connectAutocomplete-test.ts | 7 ++- .../autocomplete/connectAutocomplete.ts | 6 +-- .../breadcrumb/connectBreadcrumb.ts | 4 +- .../connectClearRefinements.ts | 4 +- .../connectConfigureRelatedItems-test.ts | 2 +- .../connectConfigureRelatedItems.ts | 10 ++-- .../__tests__/connectConfigure-test.ts | 6 +-- src/connectors/configure/connectConfigure.ts | 5 +- .../connectCurrentRefinements-test.ts | 7 ++- .../connectCurrentRefinements.ts | 6 +-- .../__tests__/connectDynamicWidgets-test.ts | 2 +- .../dynamic-widgets/connectDynamicWidgets.ts | 4 +- src/connectors/geo-search/connectGeoSearch.ts | 9 ++-- .../connectHierarchicalMenu.ts | 6 +-- .../__tests__/connectHitsPerPage-test.ts | 2 +- .../hits-per-page/connectHitsPerPage.ts | 7 ++- .../hits/__tests__/connectHits-test.ts | 6 ++- .../__tests__/connectHitsWithInsights-test.ts | 2 +- src/connectors/hits/connectHits.ts | 7 ++- .../hits/connectHitsWithInsights.ts | 8 ++- .../__tests__/connectInfiniteHits-test.ts | 12 +++-- .../connectInfiniteHitsWithInsights-test.ts | 7 ++- .../infinite-hits/connectInfiniteHits.ts | 7 ++- .../connectInfiniteHitsWithInsights.ts | 5 +- .../menu/__tests__/connectMenu-test.ts | 5 +- src/connectors/menu/connectMenu.ts | 4 +- .../__tests__/connectNumericMenu-test.ts | 3 +- .../numeric-menu/connectNumericMenu.ts | 11 ++-- .../__tests__/connectPagination-test.ts | 3 +- .../pagination/connectPagination.ts | 4 +- src/connectors/powered-by/connectPoweredBy.ts | 2 +- .../__tests__/connectQueryRules-test.ts | 4 +- .../query-rules/connectQueryRules.ts | 6 +-- .../range/__tests__/connectRange-test.ts | 2 +- src/connectors/range/connectRange.ts | 8 +-- .../rating-menu/connectRatingMenu.ts | 6 +-- .../refinement-list/connectRefinementList.ts | 6 +-- .../relevant-sort/connectRelevantSort.ts | 2 +- .../__tests__/connectSearchBox-test.ts | 2 +- src/connectors/search-box/connectSearchBox.ts | 4 +- .../sort-by/__tests__/connectSortBy-test.ts | 3 +- src/connectors/sort-by/connectSortBy.ts | 2 +- .../stats/__tests__/connectStats-test.ts | 3 +- src/connectors/stats/connectStats.ts | 2 +- .../__tests__/connectToggleRefinement-test.ts | 5 +- .../connectToggleRefinement.ts | 4 +- src/connectors/toggle-refinement/types.ts | 4 +- .../__tests__/connectVoiceSearch-test.ts | 2 +- .../voice-search/connectVoiceSearch.ts | 6 +-- src/helpers/highlight.ts | 2 +- src/helpers/insights.ts | 2 +- src/helpers/reverseHighlight.ts | 2 +- src/helpers/reverseSnippet.ts | 2 +- src/helpers/snippet.ts | 2 +- src/index.es.ts | 5 +- src/index.ts | 5 +- src/lib/InstantSearch.ts | 16 +++--- .../InstantSearch-integration-test.ts | 2 +- src/lib/__tests__/InstantSearch-test.tsx | 11 ++-- src/lib/__tests__/RoutingManager-test.ts | 4 +- src/lib/__tests__/insights-client-test.ts | 2 +- src/lib/createHelpers.ts | 12 +++-- src/lib/infiniteHitsCache/sessionStorage.ts | 4 +- src/lib/insights/client.ts | 4 +- src/lib/insights/listener.tsx | 4 +- src/lib/routers/history.ts | 2 +- .../stateMappings/__tests__/simple-test.ts | 2 +- .../__tests__/singleIndex-test.ts | 2 +- src/lib/stateMappings/simple.ts | 2 +- src/lib/stateMappings/singleIndex.ts | 2 +- .../utils/__tests__/clearRefinements-test.ts | 2 +- .../__tests__/createSendEventForFacet-test.ts | 2 +- src/lib/utils/__tests__/geo-search-test.ts | 2 +- .../getHighlightFromSiblings-test.ts | 2 +- .../utils/__tests__/getRefinements-test.ts | 2 +- .../utils/__tests__/renderTemplate-test.ts | 2 +- src/lib/utils/checkIndexUiState.ts | 4 +- src/lib/utils/checkRendering.ts | 2 +- src/lib/utils/clearRefinements.ts | 2 +- src/lib/utils/concatHighlightedParts.ts | 2 +- .../convertNumericRefinementsToFilters.ts | 2 +- src/lib/utils/createSendEventForFacet.ts | 4 +- src/lib/utils/createSendEventForHits.ts | 4 +- src/lib/utils/debounce.ts | 2 +- src/lib/utils/escape-highlight.ts | 2 +- src/lib/utils/getHighlightFromSiblings.ts | 2 +- src/lib/utils/getRefinements.ts | 2 +- src/lib/utils/getWidgetAttribute.ts | 4 +- src/lib/utils/hits-absolute-position.ts | 2 +- src/lib/utils/hits-query-id.ts | 2 +- src/lib/utils/isFacetRefined.ts | 2 +- src/lib/utils/mergeSearchParameters.ts | 2 +- src/lib/utils/prepareTemplateProps.ts | 4 +- src/lib/utils/renderTemplate.ts | 7 +-- src/lib/utils/resolveSearchParameters.ts | 4 +- src/lib/utils/reverseHighlightedParts.ts | 2 +- src/lib/voiceSearchHelper/index.ts | 6 ++- .../__tests__/createInsightsMiddleware.ts | 2 +- src/middlewares/createInsightsMiddleware.ts | 2 +- src/middlewares/createMetadataMiddleware.ts | 4 +- src/middlewares/createRouterMiddleware.ts | 2 +- src/types/algoliasearch.ts | 6 +-- src/types/connector.ts | 10 ++-- src/types/instantsearch.ts | 2 +- src/types/middleware.ts | 6 +-- src/types/render-state.ts | 54 +++++++++---------- src/types/router.ts | 2 +- src/types/templates.ts | 2 +- src/types/ui-state.ts | 36 ++++++------- src/types/widget-factory.ts | 2 +- src/types/widget.ts | 12 ++--- src/widgets/__tests__/index.test.ts | 6 +-- src/widgets/analytics/analytics.ts | 4 +- src/widgets/answers/answers.tsx | 10 ++-- src/widgets/answers/defaultTemplates.ts | 2 +- .../breadcrumb/__tests__/breadcrumb-test.ts | 5 +- src/widgets/breadcrumb/breadcrumb.tsx | 10 ++-- src/widgets/breadcrumb/defaultTemplates.ts | 2 +- .../__tests__/clear-refinements-test.ts | 5 +- .../clear-refinements/clear-refinements.tsx | 10 ++-- .../clear-refinements/defaultTemplates.ts | 2 +- .../__tests__/configure-related-items-test.ts | 5 +- .../configure-related-items.ts | 7 +-- src/widgets/configure/configure.ts | 5 +- .../__tests__/current-refinements-test.ts | 5 +- .../current-refinements.tsx | 5 +- .../dynamic-widgets/dynamic-widgets.ts | 5 +- src/widgets/geo-search/GeoSearchRenderer.d.ts | 10 ++-- src/widgets/geo-search/defaultTemplates.ts | 2 +- src/widgets/geo-search/geo-search.ts | 8 +-- .../__tests__/hierarchical-menu-test.ts | 11 ++-- .../hierarchical-menu/defaultTemplates.ts | 2 +- .../hierarchical-menu/hierarchical-menu.tsx | 7 +-- .../__tests__/hits-per-page-test.ts | 12 +++-- src/widgets/hits-per-page/hits-per-page.tsx | 5 +- src/widgets/hits/__tests__/hits-test.ts | 9 ++-- src/widgets/hits/defaultTemplates.ts | 2 +- src/widgets/hits/hits.tsx | 12 +++-- src/widgets/index/__tests__/index-test.ts | 9 ++-- src/widgets/index/index.ts | 5 +- .../infinite-hits-integration-test.ts | 4 +- .../__tests__/infinite-hits-test.ts | 15 +++--- src/widgets/infinite-hits/defaultTemplates.ts | 2 +- src/widgets/infinite-hits/infinite-hits.tsx | 14 ++--- .../menu-select/__tests__/menu-select-test.ts | 5 +- src/widgets/menu-select/defaultTemplates.ts | 2 +- src/widgets/menu-select/menu-select.tsx | 10 ++-- src/widgets/menu/__tests__/menu-test.ts | 3 +- src/widgets/menu/defaultTemplates.ts | 2 +- src/widgets/menu/menu.tsx | 7 +-- .../__tests__/numeric-menu-test.ts | 11 ++-- src/widgets/numeric-menu/defaultTemplates.ts | 2 +- src/widgets/numeric-menu/numeric-menu.tsx | 7 +-- .../pagination/__tests__/pagination-test.ts | 5 +- src/widgets/pagination/pagination.tsx | 8 +-- src/widgets/panel/__tests__/panel-test.ts | 7 +-- src/widgets/panel/panel.tsx | 5 +- src/widgets/places/__tests__/places-test.ts | 2 +- src/widgets/places/places.ts | 4 +- .../powered-by/__tests__/powered-by-test.ts | 8 +-- src/widgets/powered-by/powered-by.tsx | 10 ++-- .../query-rule-context/query-rule-context.tsx | 5 +- .../__tests__/query-rule-custom-data-test.ts | 10 ++-- .../query-rule-custom-data.tsx | 10 ++-- .../range-input/__tests__/range-input-test.ts | 8 +-- src/widgets/range-input/range-input.tsx | 10 ++-- .../__tests__/range-slider-test.ts | 7 +-- src/widgets/range-slider/range-slider.tsx | 10 ++-- .../rating-menu/__tests__/rating-menu-test.ts | 3 +- src/widgets/rating-menu/defaultTemplates.ts | 2 +- src/widgets/rating-menu/rating-menu.tsx | 7 +-- .../__tests__/refinement-list-test.ts | 16 +++--- .../refinement-list/defaultTemplates.ts | 2 +- .../refinement-list/refinement-list.tsx | 16 +++--- .../__tests__/relevant-sort-test.ts | 3 +- src/widgets/relevant-sort/defaultTemplates.ts | 2 +- src/widgets/relevant-sort/relevant-sort.tsx | 10 ++-- .../search-box/__tests__/search-box-test.ts | 6 ++- src/widgets/search-box/defaultTemplates.ts | 2 +- src/widgets/search-box/search-box.tsx | 8 +-- src/widgets/sort-by/__tests__/sort-by-test.ts | 9 ++-- src/widgets/sort-by/sort-by.tsx | 10 ++-- src/widgets/stats/stats.tsx | 10 ++-- .../__tests__/toggle-refinement-test.ts | 9 ++-- .../toggle-refinement/defaultTemplates.ts | 2 +- .../toggle-refinement/toggle-refinement.tsx | 10 ++-- .../__tests__/voice-search-test.ts | 14 ++--- src/widgets/voice-search/defaultTemplates.ts | 2 +- src/widgets/voice-search/voice-search.tsx | 12 +++-- stories/configure-related-items.stories.ts | 4 +- test/mock/createAPIResponse.ts | 2 +- test/mock/createInstantSearch.ts | 2 +- test/mock/createSearchClient.ts | 2 +- test/mock/createWidget.ts | 2 +- test/utils/enzyme.ts | 5 +- test/utils/widgetSnapshotSerializer.ts | 4 +- tsconfig.json | 3 +- 239 files changed, 723 insertions(+), 610 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f8250bec61..d61dd21569 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -51,6 +51,7 @@ module.exports = { }, }, ], + '@typescript-eslint/consistent-type-imports': 'error', }, overrides: [ { diff --git a/examples/e-commerce/src/routing.ts b/examples/e-commerce/src/routing.ts index 3ca55085ed..cbf5d2b9d7 100644 --- a/examples/e-commerce/src/routing.ts +++ b/examples/e-commerce/src/routing.ts @@ -1,9 +1,7 @@ /* eslint complexity: off */ -import { - history as historyRouter, - UiState, -} from 'instantsearch.js/es/lib/routers'; +import type { UiState } from 'instantsearch.js/es/lib/routers'; +import { history as historyRouter } from 'instantsearch.js/es/lib/routers'; import { getFallbackHitsPerPageRoutingValue, getFallbackSortByRoutingValue, diff --git a/scripts/jest/matchers/__tests__/toWarnDev-test.ts b/scripts/jest/matchers/__tests__/toWarnDev-test.ts index cd3a032c26..7f8c45bd6d 100644 --- a/scripts/jest/matchers/__tests__/toWarnDev-test.ts +++ b/scripts/jest/matchers/__tests__/toWarnDev-test.ts @@ -1,5 +1,9 @@ /* eslint-disable no-console */ +// export is needed for TS isolatedModules +// eslint-disable-next-line jest/no-export +export {}; + describe('toWarnDev', () => { describe('usage', () => { test('fails with incorrect type of message', () => { diff --git a/src/components/Answers/Answers.tsx b/src/components/Answers/Answers.tsx index 863957ab56..2bcbc71fd1 100644 --- a/src/components/Answers/Answers.tsx +++ b/src/components/Answers/Answers.tsx @@ -3,11 +3,11 @@ import { h } from 'preact'; import cx from 'classnames'; import Template from '../Template/Template'; -import { +import type { AnswersCSSClasses, AnswersTemplates, } from '../../widgets/answers/answers'; -import { ComponentCSSClasses, Hits } from '../../types'; +import type { ComponentCSSClasses, Hits } from '../../types'; export type AnswersComponentCSSClasses = ComponentCSSClasses; diff --git a/src/components/Answers/__tests__/Answers-test.tsx b/src/components/Answers/__tests__/Answers-test.tsx index b201b891b4..7a6e2a4d53 100644 --- a/src/components/Answers/__tests__/Answers-test.tsx +++ b/src/components/Answers/__tests__/Answers-test.tsx @@ -2,7 +2,8 @@ import { h } from 'preact'; import { render } from '@testing-library/preact'; -import Answers, { AnswersProps } from '../Answers'; +import type { AnswersProps } from '../Answers'; +import Answers from '../Answers'; const defaultProps: AnswersProps = { hits: [], diff --git a/src/components/Breadcrumb/Breadcrumb.tsx b/src/components/Breadcrumb/Breadcrumb.tsx index 38a7b6d989..01b2a6be2c 100644 --- a/src/components/Breadcrumb/Breadcrumb.tsx +++ b/src/components/Breadcrumb/Breadcrumb.tsx @@ -3,13 +3,13 @@ import { h } from 'preact'; import cx from 'classnames'; import Template from '../Template/Template'; -import { +import type { BreadcrumbCSSClasses, BreadcrumbTemplates, } from '../../widgets/breadcrumb/breadcrumb'; -import { ComponentCSSClasses } from '../../types'; -import { PreparedTemplateProps } from '../../lib/utils/prepareTemplateProps'; -import { BreadcrumbConnectorParamsItem } from '../../connectors/breadcrumb/connectBreadcrumb'; +import type { ComponentCSSClasses } from '../../types'; +import type { PreparedTemplateProps } from '../../lib/utils/prepareTemplateProps'; +import type { BreadcrumbConnectorParamsItem } from '../../connectors/breadcrumb/connectBreadcrumb'; export type BreadcrumbComponentCSSClasses = ComponentCSSClasses; diff --git a/src/components/Breadcrumb/__tests__/Breadcrumb-test.tsx b/src/components/Breadcrumb/__tests__/Breadcrumb-test.tsx index 8231cef555..85cf7d9f1b 100644 --- a/src/components/Breadcrumb/__tests__/Breadcrumb-test.tsx +++ b/src/components/Breadcrumb/__tests__/Breadcrumb-test.tsx @@ -2,7 +2,8 @@ import { h } from 'preact'; import { render, fireEvent } from '@testing-library/preact'; -import Breadcrumb, { BreadcrumbProps } from '../Breadcrumb'; +import type { BreadcrumbProps } from '../Breadcrumb'; +import Breadcrumb from '../Breadcrumb'; import { prepareTemplateProps } from '../../../lib/utils'; import defaultTemplates from '../../../widgets/breadcrumb/defaultTemplates'; diff --git a/src/components/ClearRefinements/ClearRefinements.tsx b/src/components/ClearRefinements/ClearRefinements.tsx index ef32af8844..82c31530f1 100644 --- a/src/components/ClearRefinements/ClearRefinements.tsx +++ b/src/components/ClearRefinements/ClearRefinements.tsx @@ -3,13 +3,13 @@ import { h } from 'preact'; import cx from 'classnames'; import Template from '../Template/Template'; -import { ClearRefinementsRenderState } from '../../connectors/clear-refinements/connectClearRefinements'; -import { +import type { ClearRefinementsRenderState } from '../../connectors/clear-refinements/connectClearRefinements'; +import type { ClearRefinementsCSSClasses, ClearRefinementsTemplates, } from '../../widgets/clear-refinements/clear-refinements'; -import { ComponentCSSClasses } from '../../types'; -import { PreparedTemplateProps } from '../../lib/utils/prepareTemplateProps'; +import type { ComponentCSSClasses } from '../../types'; +import type { PreparedTemplateProps } from '../../lib/utils/prepareTemplateProps'; export type ClearRefinementsComponentCSSClasses = ComponentCSSClasses; diff --git a/src/components/CurrentRefinements/CurrentRefinements.tsx b/src/components/CurrentRefinements/CurrentRefinements.tsx index cd2f0d5aa2..a06586a727 100644 --- a/src/components/CurrentRefinements/CurrentRefinements.tsx +++ b/src/components/CurrentRefinements/CurrentRefinements.tsx @@ -2,12 +2,12 @@ import { h } from 'preact'; import { isSpecialClick, capitalize } from '../../lib/utils'; -import { +import type { CurrentRefinementsConnectorParamsItem, CurrentRefinementsConnectorParamsRefinement, } from '../../connectors/current-refinements/connectCurrentRefinements'; -import { CurrentRefinementsCSSClasses } from '../../widgets/current-refinements/current-refinements'; -import { ComponentCSSClasses } from '../../types'; +import type { CurrentRefinementsCSSClasses } from '../../widgets/current-refinements/current-refinements'; +import type { ComponentCSSClasses } from '../../types'; export type CurrentRefinementsComponentCSSClasses = ComponentCSSClasses; diff --git a/src/components/GeoSearchControls/GeoSearchButton.tsx b/src/components/GeoSearchControls/GeoSearchButton.tsx index 695b81a7bd..0667543dc0 100644 --- a/src/components/GeoSearchControls/GeoSearchButton.tsx +++ b/src/components/GeoSearchControls/GeoSearchButton.tsx @@ -1,6 +1,7 @@ /** @jsx h */ -import { h, ComponentChildren } from 'preact'; +import type { ComponentChildren } from 'preact'; +import { h } from 'preact'; type Props = { className: string; diff --git a/src/components/GeoSearchControls/GeoSearchControls.tsx b/src/components/GeoSearchControls/GeoSearchControls.tsx index 3e2add2016..6a40638b50 100644 --- a/src/components/GeoSearchControls/GeoSearchControls.tsx +++ b/src/components/GeoSearchControls/GeoSearchControls.tsx @@ -5,12 +5,12 @@ import cx from 'classnames'; import Template from '../Template/Template'; import GeoSearchButton from './GeoSearchButton'; import GeoSearchToggle from './GeoSearchToggle'; -import { +import type { GeoSearchCSSClasses, GeoSearchTemplates, } from '../../widgets/geo-search/geo-search'; -import { ComponentCSSClasses } from '../../types'; -import { PreparedTemplateProps } from '../../lib/utils/prepareTemplateProps'; +import type { ComponentCSSClasses } from '../../types'; +import type { PreparedTemplateProps } from '../../lib/utils/prepareTemplateProps'; type Props = { cssClasses: ComponentCSSClasses; diff --git a/src/components/GeoSearchControls/GeoSearchToggle.tsx b/src/components/GeoSearchControls/GeoSearchToggle.tsx index 945914e937..62e98ef506 100644 --- a/src/components/GeoSearchControls/GeoSearchToggle.tsx +++ b/src/components/GeoSearchControls/GeoSearchToggle.tsx @@ -1,6 +1,7 @@ /** @jsx h */ -import { h, ComponentChildren } from 'preact'; +import type { ComponentChildren } from 'preact'; +import { h } from 'preact'; type Props = { classNameLabel: string; diff --git a/src/components/Hits/Hits.tsx b/src/components/Hits/Hits.tsx index 119e796f61..5cbfd2fd15 100644 --- a/src/components/Hits/Hits.tsx +++ b/src/components/Hits/Hits.tsx @@ -3,11 +3,11 @@ import { h } from 'preact'; import cx from 'classnames'; import Template from '../Template/Template'; -import { SearchResults } from 'algoliasearch-helper'; -import { BindEventForHits, SendEventForHits } from '../../lib/utils'; -import { ComponentCSSClasses, Hits as HitsArray } from '../../types'; -import { HitsCSSClasses, HitsTemplates } from '../../widgets/hits/hits'; -import { PreparedTemplateProps } from '../../lib/utils/prepareTemplateProps'; +import type { SearchResults } from 'algoliasearch-helper'; +import type { BindEventForHits, SendEventForHits } from '../../lib/utils'; +import type { ComponentCSSClasses, Hits as HitsArray } from '../../types'; +import type { HitsCSSClasses, HitsTemplates } from '../../widgets/hits/hits'; +import type { PreparedTemplateProps } from '../../lib/utils/prepareTemplateProps'; export type HitsComponentCSSClasses = ComponentCSSClasses; export type HitsComponentTemplates = Required; diff --git a/src/components/Hits/__tests__/Hits-test.tsx b/src/components/Hits/__tests__/Hits-test.tsx index 5b2f50433b..d12baa1254 100644 --- a/src/components/Hits/__tests__/Hits-test.tsx +++ b/src/components/Hits/__tests__/Hits-test.tsx @@ -5,7 +5,8 @@ import { shallow, mount } from '../../../../test/utils/enzyme'; import { highlight } from '../../../helpers'; import { prepareTemplateProps, TAG_REPLACEMENT } from '../../../lib/utils'; import Template from '../../Template/Template'; -import Hits, { HitsProps } from '../Hits'; +import type { HitsProps } from '../Hits'; +import Hits from '../Hits'; import { createSingleSearchResponse } from '../../../../test/mock/createAPIResponse'; import { SearchParameters, SearchResults } from 'algoliasearch-helper'; import defaultTemplates from '../../../widgets/hits/defaultTemplates'; diff --git a/src/components/InfiniteHits/InfiniteHits.tsx b/src/components/InfiniteHits/InfiniteHits.tsx index d29a1be715..0cf5f6a58f 100644 --- a/src/components/InfiniteHits/InfiniteHits.tsx +++ b/src/components/InfiniteHits/InfiniteHits.tsx @@ -3,13 +3,13 @@ import { h } from 'preact'; import cx from 'classnames'; import Template from '../Template/Template'; -import { SearchResults } from 'algoliasearch-helper'; -import { ComponentCSSClasses, Hits } from '../../types'; -import { +import type { SearchResults } from 'algoliasearch-helper'; +import type { ComponentCSSClasses, Hits } from '../../types'; +import type { InfiniteHitsCSSClasses, InfiniteHitsTemplates, } from '../../widgets/infinite-hits/infinite-hits'; -import { SendEventForHits, BindEventForHits } from '../../lib/utils'; +import type { SendEventForHits, BindEventForHits } from '../../lib/utils'; export type InfiniteHitsComponentCSSClasses = ComponentCSSClasses; diff --git a/src/components/InfiniteHits/__tests__/InfiniteHits-test.tsx b/src/components/InfiniteHits/__tests__/InfiniteHits-test.tsx index a3d3e64454..e1eec8aef6 100644 --- a/src/components/InfiniteHits/__tests__/InfiniteHits-test.tsx +++ b/src/components/InfiniteHits/__tests__/InfiniteHits-test.tsx @@ -4,7 +4,7 @@ import { h } from 'preact'; import { render } from '@testing-library/preact'; import { SearchParameters, SearchResults } from 'algoliasearch-helper'; import InfiniteHits from '../InfiniteHits'; -import { Hits, SearchResponse } from '../../../types'; +import type { Hits, SearchResponse } from '../../../types'; import { createSingleSearchResponse } from '../../../../test/mock/createAPIResponse'; function createResults(partialResults: Partial>) { diff --git a/src/components/MenuSelect/MenuSelect.tsx b/src/components/MenuSelect/MenuSelect.tsx index 8712663a6d..d71f24a24c 100644 --- a/src/components/MenuSelect/MenuSelect.tsx +++ b/src/components/MenuSelect/MenuSelect.tsx @@ -4,12 +4,12 @@ import { h } from 'preact'; import cx from 'classnames'; import { find } from '../../lib/utils'; import Template from '../Template/Template'; -import { +import type { MenuSelectCSSClasses, MenuSelectTemplates, } from '../../widgets/menu-select/menu-select'; -import { MenuRenderState } from '../../connectors/menu/connectMenu'; -import { ComponentCSSClasses } from '../../types'; +import type { MenuRenderState } from '../../connectors/menu/connectMenu'; +import type { ComponentCSSClasses } from '../../types'; export type MenuSelectComponentCSSClasses = ComponentCSSClasses; diff --git a/src/components/Pagination/Pagination.tsx b/src/components/Pagination/Pagination.tsx index 75ec53ecf6..c66ab675b0 100644 --- a/src/components/Pagination/Pagination.tsx +++ b/src/components/Pagination/Pagination.tsx @@ -5,11 +5,11 @@ import cx from 'classnames'; import PaginationLink from './PaginationLink'; import { isSpecialClick } from '../../lib/utils'; -import { +import type { PaginationCSSClasses, PaginationTemplates, } from '../../widgets/pagination/pagination'; -import { ComponentCSSClasses } from '../../types'; +import type { ComponentCSSClasses } from '../../types'; export type PaginationComponentCSSClasses = ComponentCSSClasses; diff --git a/src/components/Pagination/__tests__/Pagination-test.tsx b/src/components/Pagination/__tests__/Pagination-test.tsx index 6cbb4460be..a563776d37 100644 --- a/src/components/Pagination/__tests__/Pagination-test.tsx +++ b/src/components/Pagination/__tests__/Pagination-test.tsx @@ -2,7 +2,8 @@ import { h } from 'preact'; import { mount } from '../../../../test/utils/enzyme'; -import Pagination, { PaginationProps } from '../Pagination'; +import type { PaginationProps } from '../Pagination'; +import Pagination from '../Pagination'; import Paginator from '../../../connectors/pagination/Paginator'; describe('Pagination', () => { diff --git a/src/components/Panel/Panel.tsx b/src/components/Panel/Panel.tsx index 942135642b..dfc0df3e8b 100644 --- a/src/components/Panel/Panel.tsx +++ b/src/components/Panel/Panel.tsx @@ -4,8 +4,11 @@ import { h } from 'preact'; import { useState, useEffect, useRef } from 'preact/hooks'; import cx from 'classnames'; import Template from '../Template/Template'; -import { PanelCSSClasses, PanelTemplates } from '../../widgets/panel/panel'; -import { +import type { + PanelCSSClasses, + PanelTemplates, +} from '../../widgets/panel/panel'; +import type { ComponentCSSClasses, RenderOptions, UnknownWidgetFactory, diff --git a/src/components/Panel/__tests__/Panel-test.tsx b/src/components/Panel/__tests__/Panel-test.tsx index b3673206e3..4d2d5913bf 100644 --- a/src/components/Panel/__tests__/Panel-test.tsx +++ b/src/components/Panel/__tests__/Panel-test.tsx @@ -2,7 +2,8 @@ import { h } from 'preact'; import { render, fireEvent } from '@testing-library/preact'; -import Panel, { PanelProps } from '../Panel'; +import type { PanelProps } from '../Panel'; +import Panel from '../Panel'; import { createRenderOptions } from '../../../../test/mock/createWidget'; const cssClasses = { diff --git a/src/components/PoweredBy/PoweredBy.tsx b/src/components/PoweredBy/PoweredBy.tsx index 0cfef90509..373d75e4af 100644 --- a/src/components/PoweredBy/PoweredBy.tsx +++ b/src/components/PoweredBy/PoweredBy.tsx @@ -1,8 +1,8 @@ /** @jsx h */ import { h } from 'preact'; -import { ComponentCSSClasses } from '../../types'; -import { PoweredByCSSClasses } from '../../widgets/powered-by/powered-by'; +import type { ComponentCSSClasses } from '../../types'; +import type { PoweredByCSSClasses } from '../../widgets/powered-by/powered-by'; export type PoweredByComponentCSSClasses = ComponentCSSClasses; diff --git a/src/components/QueryRuleCustomData/QueryRuleCustomData.tsx b/src/components/QueryRuleCustomData/QueryRuleCustomData.tsx index fd8494311e..145d6f10f1 100644 --- a/src/components/QueryRuleCustomData/QueryRuleCustomData.tsx +++ b/src/components/QueryRuleCustomData/QueryRuleCustomData.tsx @@ -1,8 +1,8 @@ /** @jsx h */ import { h } from 'preact'; -import { ComponentCSSClasses } from '../../types'; -import { +import type { ComponentCSSClasses } from '../../types'; +import type { QueryRuleCustomDataCSSClasses, QueryRuleCustomDataTemplates, } from '../../widgets/query-rule-custom-data/query-rule-custom-data'; diff --git a/src/components/RangeInput/RangeInput.tsx b/src/components/RangeInput/RangeInput.tsx index 60a4b04897..99bd8e5a4d 100644 --- a/src/components/RangeInput/RangeInput.tsx +++ b/src/components/RangeInput/RangeInput.tsx @@ -3,12 +3,15 @@ import { h, Component } from 'preact'; import cx from 'classnames'; import Template from '../Template/Template'; -import { +import type { RangeInputCSSClasses, RangeInputTemplates, } from '../../widgets/range-input/range-input'; -import { Range, RangeBoundaries } from '../../connectors/range/connectRange'; -import { ComponentCSSClasses } from '../../types'; +import type { + Range, + RangeBoundaries, +} from '../../connectors/range/connectRange'; +import type { ComponentCSSClasses } from '../../types'; export type RangeInputComponentCSSClasses = ComponentCSSClasses; diff --git a/src/components/RangeInput/__tests__/RangeInput-test.tsx b/src/components/RangeInput/__tests__/RangeInput-test.tsx index 226d56b2de..2a0b109ff8 100644 --- a/src/components/RangeInput/__tests__/RangeInput-test.tsx +++ b/src/components/RangeInput/__tests__/RangeInput-test.tsx @@ -3,7 +3,8 @@ import { h } from 'preact'; import { shallow } from '../../../../test/utils/enzyme'; import { render, fireEvent } from '@testing-library/preact'; -import RangeInput, { RangeInputProps } from '../RangeInput'; +import type { RangeInputProps } from '../RangeInput'; +import RangeInput from '../RangeInput'; describe('RangeInput', () => { const defaultProps: RangeInputProps = { diff --git a/src/components/RefinementList/RefinementList.tsx b/src/components/RefinementList/RefinementList.tsx index 5516bc488f..586f3d13b6 100644 --- a/src/components/RefinementList/RefinementList.tsx +++ b/src/components/RefinementList/RefinementList.tsx @@ -1,20 +1,22 @@ /** @jsx h */ +import type { JSX } from 'preact'; import { h, createRef, Component } from 'preact'; import cx from 'classnames'; import { isSpecialClick, isEqual } from '../../lib/utils'; -import { PreparedTemplateProps } from '../../lib/utils/prepareTemplateProps'; +import type { PreparedTemplateProps } from '../../lib/utils/prepareTemplateProps'; import Template from '../Template/Template'; import RefinementListItem from './RefinementListItem'; -import SearchBox, { +import type { SearchBoxComponentCSSClasses, SearchBoxComponentTemplates, } from '../SearchBox/SearchBox'; -import { HierarchicalMenuItem } from '../../connectors/hierarchical-menu/connectHierarchicalMenu'; -import { ComponentCSSClasses, CreateURL, Templates } from '../../types'; -import { RefinementListOwnCSSClasses } from '../../widgets/refinement-list/refinement-list'; -import { RatingMenuComponentCSSClasses } from '../../widgets/rating-menu/rating-menu'; -import { HierarchicalMenuComponentCSSClasses } from '../../widgets/hierarchical-menu/hierarchical-menu'; +import SearchBox from '../SearchBox/SearchBox'; +import type { HierarchicalMenuItem } from '../../connectors/hierarchical-menu/connectHierarchicalMenu'; +import type { ComponentCSSClasses, CreateURL, Templates } from '../../types'; +import type { RefinementListOwnCSSClasses } from '../../widgets/refinement-list/refinement-list'; +import type { RatingMenuComponentCSSClasses } from '../../widgets/rating-menu/rating-menu'; +import type { HierarchicalMenuComponentCSSClasses } from '../../widgets/hierarchical-menu/hierarchical-menu'; // CSS types type RefinementListOptionalClasses = @@ -66,7 +68,7 @@ export type RefinementListProps = { hasExhaustiveItems?: boolean; canToggleShowMore?: boolean; className?: string; - children?: h.JSX.Element; + children?: JSX.Element; // searchable props are optional, but will definitely be present in a searchable context isFromSearch?: boolean; diff --git a/src/components/RefinementList/RefinementListItem.tsx b/src/components/RefinementList/RefinementListItem.tsx index 39ee76912a..9aac0722ec 100644 --- a/src/components/RefinementList/RefinementListItem.tsx +++ b/src/components/RefinementList/RefinementListItem.tsx @@ -1,5 +1,6 @@ /** @jsx h */ +import type { JSX } from 'preact'; import { h } from 'preact'; import Template from '../Template/Template'; @@ -11,7 +12,7 @@ export type RefinementListItemProps = { originalEvent: MouseEvent; }) => void; isRefined: boolean; - subItems?: h.JSX.Element; + subItems?: JSX.Element; templateData: Record; templateKey: string; templateProps?: Record; diff --git a/src/components/RefinementList/__tests__/RefinementList-test.tsx b/src/components/RefinementList/__tests__/RefinementList-test.tsx index 90f0ec386b..83ebf0fbd1 100644 --- a/src/components/RefinementList/__tests__/RefinementList-test.tsx +++ b/src/components/RefinementList/__tests__/RefinementList-test.tsx @@ -2,9 +2,10 @@ import { h } from 'preact'; import { render, fireEvent } from '@testing-library/preact'; -import RefinementList, { RefinementListProps } from '../RefinementList'; +import type { RefinementListProps } from '../RefinementList'; +import RefinementList from '../RefinementList'; import defaultTemplates from '../../../widgets/refinement-list/defaultTemplates'; -import { +import type { RefinementListItemData, RefinementListTemplates, } from '../../../widgets/refinement-list/refinement-list'; diff --git a/src/components/RefinementList/__tests__/RefinementListItem-test.tsx b/src/components/RefinementList/__tests__/RefinementListItem-test.tsx index f82efcde6a..58648e4ecc 100644 --- a/src/components/RefinementList/__tests__/RefinementListItem-test.tsx +++ b/src/components/RefinementList/__tests__/RefinementListItem-test.tsx @@ -2,9 +2,8 @@ import { h } from 'preact'; import { shallow } from '../../../../test/utils/enzyme'; -import RefinementListItem, { - RefinementListItemProps, -} from '../RefinementListItem'; +import type { RefinementListItemProps } from '../RefinementListItem'; +import RefinementListItem from '../RefinementListItem'; describe('RefinementListItem', () => { const props: RefinementListItemProps = { diff --git a/src/components/RelevantSort/RelevantSort.tsx b/src/components/RelevantSort/RelevantSort.tsx index bbd5933a74..6a61108a97 100644 --- a/src/components/RelevantSort/RelevantSort.tsx +++ b/src/components/RelevantSort/RelevantSort.tsx @@ -2,11 +2,11 @@ import { h } from 'preact'; import Template from '../Template/Template'; -import { +import type { RelevantSortCSSClasses, RelevantSortTemplates, } from '../../widgets/relevant-sort/relevant-sort'; -import { ComponentCSSClasses } from '../../types'; +import type { ComponentCSSClasses } from '../../types'; export type RelevantSortComponentCSSClasses = ComponentCSSClasses; diff --git a/src/components/RelevantSort/__tests__/RelevantSort-test.tsx b/src/components/RelevantSort/__tests__/RelevantSort-test.tsx index c375571d2a..4bef25f3dd 100644 --- a/src/components/RelevantSort/__tests__/RelevantSort-test.tsx +++ b/src/components/RelevantSort/__tests__/RelevantSort-test.tsx @@ -3,7 +3,8 @@ import { h } from 'preact'; import { render, fireEvent } from '@testing-library/preact'; -import RelevantSort, { RelevantSortComponentTemplates } from '../RelevantSort'; +import type { RelevantSortComponentTemplates } from '../RelevantSort'; +import RelevantSort from '../RelevantSort'; const cssClasses = { root: 'root', diff --git a/src/components/SearchBox/SearchBox.tsx b/src/components/SearchBox/SearchBox.tsx index c93053b005..d935991da1 100644 --- a/src/components/SearchBox/SearchBox.tsx +++ b/src/components/SearchBox/SearchBox.tsx @@ -3,11 +3,11 @@ import { h, createRef, Component } from 'preact'; import { noop } from '../../lib/utils'; import Template from '../Template/Template'; -import { +import type { SearchBoxCSSClasses, SearchBoxTemplates, } from '../../widgets/search-box/search-box'; -import { ComponentCSSClasses } from '../../types'; +import type { ComponentCSSClasses } from '../../types'; export type SearchBoxComponentCSSClasses = ComponentCSSClasses; diff --git a/src/components/Slider/Pit.tsx b/src/components/Slider/Pit.tsx index d341ab8d6d..f715c86b2d 100644 --- a/src/components/Slider/Pit.tsx +++ b/src/components/Slider/Pit.tsx @@ -2,7 +2,7 @@ import { h } from 'preact'; import cx from 'classnames'; -import { PitProps } from './Rheostat'; +import type { PitProps } from './Rheostat'; const Pit = ({ style, children }: PitProps) => { // first, end & middle diff --git a/src/components/Slider/Rheostat.tsx b/src/components/Slider/Rheostat.tsx index 4677572ff3..892737226e 100644 --- a/src/components/Slider/Rheostat.tsx +++ b/src/components/Slider/Rheostat.tsx @@ -6,13 +6,8 @@ /** @jsx h */ -import { - h, - Component, - ComponentChildren, - ComponentType, - createRef, -} from 'preact'; +import type { ComponentChildren, ComponentType, JSX } from 'preact'; +import { h, Component, createRef } from 'preact'; type BoundingBox = { height: number; @@ -73,11 +68,11 @@ function killEvent(ev: Event) { ev.preventDefault(); } -function Button(props: h.JSX.IntrinsicElements['button']) { +function Button(props: JSX.IntrinsicElements['button']) { return