diff --git a/package.json b/package.json index 21d77055..dfc30b7d 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "test:watch": "yarn build && vitest", "instant-meilisearch:test:watch": "vitest --project \"@meilisearch/instant-meilisearch\"", "autocomplete:test:watch": "vitest --project \"@meilisearch/autocomplete-client\"", - "test:types": "yarn build && tsc --noEmit", + "test:types": "turbo test:types", "version-packages": "changeset version && turbo version", "release": "yarn build && changeset publish" }, diff --git a/packages/autocomplete-client/package.json b/packages/autocomplete-client/package.json index af0586c0..54b793a5 100644 --- a/packages/autocomplete-client/package.json +++ b/packages/autocomplete-client/package.json @@ -8,7 +8,8 @@ }, "scripts": { "build": "vite build && tsc -p tsconfig.json", - "version": "node scripts/update_version.cjs" + "version": "node scripts/update_version.cjs", + "test:types": "tsc --noEmit" }, "type": "module", "types": "./dist/types/index.d.ts", @@ -44,8 +45,7 @@ "@meilisearch/instant-meilisearch": "*" }, "devDependencies": { - "@algolia/autocomplete-js": "^1.7.4", - "cssnano": "^4.1.10", - "instantsearch.js": "^4.56.2" + "@algolia/autocomplete-js": "^1.18.0", + "instantsearch.js": "^4.77.3" } } diff --git a/packages/instant-meilisearch/package.json b/packages/instant-meilisearch/package.json index 96ddf612..cf3c7c4c 100644 --- a/packages/instant-meilisearch/package.json +++ b/packages/instant-meilisearch/package.json @@ -25,7 +25,8 @@ ], "scripts": { "build": "vite build && tsc -p tsconfig.json", - "version": "node scripts/update_version.cjs" + "version": "node scripts/update_version.cjs", + "test:types": "tsc --noEmit" }, "type": "module", "types": "./dist/types/index.d.ts", @@ -47,7 +48,6 @@ "meilisearch": "^0.48.2" }, "devDependencies": { - "cssnano": "^4.1.10", - "instantsearch.js": "^4.56.2" + "instantsearch.js": "^4.77.3" } } diff --git a/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts b/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts index c90740f3..6529dcd5 100644 --- a/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts +++ b/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts @@ -12,6 +12,7 @@ import type { InstantMeiliSearchObject, ApiKeyCallback, } from '../types/index.js' +import type { UiState } from 'instantsearch.js/es/types/ui-state.js' import { getApiKey, getInstantMeilisearchConfig, @@ -43,11 +44,14 @@ import { constructClientAgents } from './agents.js' * `{}` * @returns {InstantMeiliSearchObject} */ -export function instantMeiliSearch( +export function instantMeiliSearch< + TUiState extends UiState = UiState, + TRouteState = TUiState, +>( hostUrl: string, apiKey: string | ApiKeyCallback = '', instantMeiliSearchOptions: InstantMeiliSearchOptions = {} -): InstantMeiliSearchObject { +): InstantMeiliSearchObject { // Validate parameters validateInstantMeiliSearchParams(hostUrl, apiKey, instantMeiliSearchOptions) diff --git a/packages/instant-meilisearch/src/types/types.ts b/packages/instant-meilisearch/src/types/types.ts index 3b0e26de..853cec9b 100644 --- a/packages/instant-meilisearch/src/types/types.ts +++ b/packages/instant-meilisearch/src/types/types.ts @@ -1,4 +1,5 @@ -import type SearchClient from 'instantsearch.js' +import type InstantSearch from 'instantsearch.js/es/lib/InstantSearch.js' +import type { UiState } from 'instantsearch.js/es/types/ui-state.js' import type { MultipleQueriesQuery as AlgoliaMultipleQueriesQuery, multipleSearchForFacetValues, @@ -127,14 +128,20 @@ export type InstantSearchGeoParams = { insidePolygon?: ReadonlyArray } -export type InstantMeiliSearchInstance = ReturnType & { +export type InstantMeiliSearchInstance< + TUiState extends UiState = UiState, + TRouteState = TUiState, +> = InstantSearch & { clearCache: () => void } -export type InstantMeiliSearchObject = { +export type InstantMeiliSearchObject< + TUiState extends UiState = UiState, + TRouteState = TUiState, +> = { meiliSearchInstance: MeiliSearch setMeiliSearchParams: (params: OverridableMeiliSearchSearchParameters) => void - searchClient: InstantMeiliSearchInstance + searchClient: InstantMeiliSearchInstance } export type MultiSearchResolver = { diff --git a/playgrounds/autocomplete/index.html b/playgrounds/autocomplete/index.html index 7e86c793..f6690b1e 100644 --- a/playgrounds/autocomplete/index.html +++ b/playgrounds/autocomplete/index.html @@ -1,16 +1,13 @@ - - + + - - - + + + Demo of Meilisearch + autocomplete.js -
-
- - + diff --git a/playgrounds/autocomplete/main.js b/playgrounds/autocomplete/main.js deleted file mode 100644 index ba14b87b..00000000 --- a/playgrounds/autocomplete/main.js +++ /dev/null @@ -1,8 +0,0 @@ -import './style.css' - -// eslint-disable-next-line no-undef -document.querySelector('#app').innerHTML = ` -
-
-
-` diff --git a/playgrounds/autocomplete/package.json b/playgrounds/autocomplete/package.json index 9c857aae..6fd8d2b6 100644 --- a/playgrounds/autocomplete/package.json +++ b/playgrounds/autocomplete/package.json @@ -3,12 +3,14 @@ "version": "0.0.0", "private": true, "description": "Javascript playground for autocomplete", + "type": "module", "scripts": { - "predev": "node setup.mjs", + "predev": "node setup.js", "dev": "vite", "setup": "node setup.mjs", "test:e2e": "concurrently --kill-others -s first \"yarn dev\" \"cypress run --env playground=local\"", - "test:e2e:watch": "concurrently --kill-others -s first \"yarn dev\" \"cypress open --env playground=local\"" + "test:e2e:watch": "concurrently --kill-others -s first \"yarn dev\" \"cypress open --env playground=local\"", + "test:types": "tsc" }, "keywords": [ "autocomplete" @@ -19,10 +21,10 @@ "author": "", "license": "ISC", "dependencies": { - "@algolia/autocomplete-core": "1.17.9", - "@algolia/autocomplete-plugin-query-suggestions": "^1.17.9", - "@algolia/autocomplete-plugin-tags": "^1.17.9", - "@algolia/autocomplete-theme-classic": "^1.17.9", + "@algolia/autocomplete-core": "^1.18.0", + "@algolia/autocomplete-plugin-query-suggestions": "^1.18.0", + "@algolia/autocomplete-plugin-tags": "^1.18.0", + "@algolia/autocomplete-theme-classic": "^1.18.0", "@meilisearch/autocomplete-client": "*" } } diff --git a/playgrounds/autocomplete/setup.mjs b/playgrounds/autocomplete/setup.js similarity index 100% rename from playgrounds/autocomplete/setup.mjs rename to playgrounds/autocomplete/setup.js diff --git a/playgrounds/autocomplete/src/app.js b/playgrounds/autocomplete/src/app.js deleted file mode 100644 index 24fb2b7b..00000000 --- a/playgrounds/autocomplete/src/app.js +++ /dev/null @@ -1,92 +0,0 @@ -import { autocomplete } from '@algolia/autocomplete-js' -import { - meilisearchAutocompleteClient, - getMeilisearchResults, -} from '@meilisearch/autocomplete-client' -import '@algolia/autocomplete-theme-classic' - -const client = meilisearchAutocompleteClient({ - url: 'http://localhost:7700', - apiKey: 'masterKey', -}) - -autocomplete({ - container: '#autocomplete', - placeholder: 'Search for games', - openOnFocus: true, - debug: true, - getSources({ query }) { - return [ - { - sourceId: 'steam-video-games', - getItems() { - const description = getMeilisearchResults({ - searchClient: client, - queries: [ - { - indexName: 'steam-video-games', - query, - params: { - hitsPerPage: 10, - attributesToSnippet: ['name:10', 'description:5'], - snippetEllipsisText: '..', - }, - }, - ], - }) - - return description - }, - templates: { - item({ item, components, html }) { - return html`
-
-
- ${item.name} -
-
-
- ${components.Highlight({ - hit: item, - attribute: 'name', - tagName: 'test', - })} -
-
- ${components.Snippet({ - hit: item, - attribute: 'description', - })} -
-
-
- -
-
-
` - }, - }, - }, - ] - }, -}) diff --git a/playgrounds/autocomplete/src/app.ts b/playgrounds/autocomplete/src/app.ts new file mode 100644 index 00000000..17724340 --- /dev/null +++ b/playgrounds/autocomplete/src/app.ts @@ -0,0 +1,95 @@ +import { autocomplete } from '@algolia/autocomplete-js' +import { + meilisearchAutocompleteClient, + getMeilisearchResults, +} from '@meilisearch/autocomplete-client' +// @ts-expect-error it doesn't have type declarations... +import '@algolia/autocomplete-theme-classic' + +const client = meilisearchAutocompleteClient({ + url: 'http://localhost:7700', + apiKey: 'masterKey', +}) + +export function setupAutocomplete(element: HTMLElement): void { + autocomplete({ + container: element, + placeholder: 'Search for games', + openOnFocus: true, + debug: true, + getSources({ query }) { + return [ + { + sourceId: 'steam-video-games', + getItems() { + const description = getMeilisearchResults({ + searchClient: client, + queries: [ + { + indexName: 'steam-video-games', + query, + params: { + hitsPerPage: 10, + attributesToSnippet: ['name:10', 'description:5'], + snippetEllipsisText: '..', + }, + }, + ], + }) + + return description + }, + templates: { + item({ item, components, html }) { + return html`
+
+
+ ${item.name} +
+
+
+ ${components.Highlight({ + hit: item, + attribute: 'name', + tagName: 'test', + })} +
+
+ ${components.Snippet({ + hit: item, + attribute: 'description', + })} +
+
+
+ +
+
+
` + }, + }, + }, + ] + }, + }) +} diff --git a/playgrounds/autocomplete/src/main.ts b/playgrounds/autocomplete/src/main.ts new file mode 100644 index 00000000..e9ea22ae --- /dev/null +++ b/playgrounds/autocomplete/src/main.ts @@ -0,0 +1,10 @@ +import './style.css' +import { setupAutocomplete } from './app.js' + +document.querySelector('#app')!.innerHTML = ` +
+
+
+` + +setupAutocomplete(document.querySelector('#autocomplete')!) diff --git a/playgrounds/autocomplete/style.css b/playgrounds/autocomplete/src/style.css similarity index 100% rename from playgrounds/autocomplete/style.css rename to playgrounds/autocomplete/src/style.css diff --git a/playgrounds/autocomplete/src/vite-env.d.ts b/playgrounds/autocomplete/src/vite-env.d.ts new file mode 100644 index 00000000..11f02fe2 --- /dev/null +++ b/playgrounds/autocomplete/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/playgrounds/autocomplete/tsconfig.json b/playgrounds/autocomplete/tsconfig.json new file mode 100644 index 00000000..92f8583f --- /dev/null +++ b/playgrounds/autocomplete/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedSideEffectImports": true + }, + "include": ["src"] +} diff --git a/playgrounds/javascript/index.html b/playgrounds/javascript/index.html index 0f327219..771abcb7 100644 --- a/playgrounds/javascript/index.html +++ b/playgrounds/javascript/index.html @@ -1,4 +1,4 @@ - + @@ -47,7 +47,6 @@

Misc

- - + diff --git a/playgrounds/javascript/package.json b/playgrounds/javascript/package.json index 66d05f8d..7aea5cb8 100644 --- a/playgrounds/javascript/package.json +++ b/playgrounds/javascript/package.json @@ -5,13 +5,15 @@ "description": "Instant-meilisearch playground written with vanilla javascript", "type": "module", "scripts": { - "dev": "vite" + "dev": "vite", + "test:types": "tsc" }, "browserslist": [ "defaults" ], "license": "MIT", "dependencies": { - "@meilisearch/instant-meilisearch": "0.24.0" + "@meilisearch/instant-meilisearch": "0.24.0", + "instantsearch.js": "^4.77.3" } } diff --git a/playgrounds/javascript/src/app.js b/playgrounds/javascript/src/app.ts similarity index 79% rename from playgrounds/javascript/src/app.js rename to playgrounds/javascript/src/app.ts index 6634ca4d..bdab3fba 100644 --- a/playgrounds/javascript/src/app.js +++ b/playgrounds/javascript/src/app.ts @@ -1,19 +1,26 @@ -/* eslint-disable no-undef */ import { instantMeiliSearch } from '@meilisearch/instant-meilisearch' +import { default as instantsearch } from 'instantsearch.js' +import { + clearRefinements, + configure, + hits, + pagination, + refinementList, + searchBox, + sortBy, +} from 'instantsearch.js/es/widgets' const search = instantsearch({ indexName: 'steam-video-games', searchClient: instantMeiliSearch( 'https://ms-adf78ae33284-106.lon.meilisearch.io', 'a63da4928426f12639e19d62886f621130f3fa9ff3c7534c5d179f0f51c4f303', - { - finitePagination: true, - } + { finitePagination: true } ).searchClient, }) search.addWidgets([ - instantsearch.widgets.sortBy({ + sortBy({ container: '#sort-by', items: [ { value: 'steam-video-games', label: 'Relevant' }, @@ -27,33 +34,33 @@ search.addWidgets([ }, ], }), - instantsearch.widgets.searchBox({ + searchBox({ container: '#searchbox', }), - instantsearch.widgets.clearRefinements({ + clearRefinements({ container: '#clear-refinements', }), - instantsearch.widgets.refinementList({ + refinementList({ container: '#genres-list', attribute: 'genres', }), - instantsearch.widgets.refinementList({ + refinementList({ container: '#players-list', attribute: 'players', }), - instantsearch.widgets.refinementList({ + refinementList({ container: '#platforms-list', attribute: 'platforms', }), - instantsearch.widgets.configure({ + configure({ hitsPerPage: 6, attributesToSnippet: ['description:150'], }), - instantsearch.widgets.refinementList({ + refinementList({ container: '#misc-list', attribute: 'misc', }), - instantsearch.widgets.hits({ + hits({ container: '#hits', templates: { item: ` @@ -72,7 +79,7 @@ search.addWidgets([ `, }, }), - instantsearch.widgets.pagination({ + pagination({ container: '#pagination', }), ]) diff --git a/playgrounds/javascript/src/vite-env.d.ts b/playgrounds/javascript/src/vite-env.d.ts new file mode 100644 index 00000000..11f02fe2 --- /dev/null +++ b/playgrounds/javascript/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/playgrounds/javascript/tsconfig.json b/playgrounds/javascript/tsconfig.json new file mode 100644 index 00000000..92f8583f --- /dev/null +++ b/playgrounds/javascript/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedSideEffectImports": true + }, + "include": ["src"] +} diff --git a/playgrounds/local-react/index.html b/playgrounds/local-react/index.html index 3251ccf8..3bce1cbb 100644 --- a/playgrounds/local-react/index.html +++ b/playgrounds/local-react/index.html @@ -9,6 +9,6 @@
- + diff --git a/playgrounds/local-react/package.json b/playgrounds/local-react/package.json index f5b685c7..1593ea9a 100644 --- a/playgrounds/local-react/package.json +++ b/playgrounds/local-react/package.json @@ -3,12 +3,14 @@ "version": "0.0.0", "private": true, "description": "React playground for instant-meilisearch", + "type": "module", "scripts": { "predev": "node setup.mjs", "dev": "vite", "setup": "node setup.mjs", "test:e2e": "concurrently --kill-others -s first \"yarn dev\" \"cypress run --env playground=local\"", - "test:e2e:watch": "concurrently --kill-others -s first \"yarn dev\" \"cypress open --env playground=local\"" + "test:e2e:watch": "concurrently --kill-others -s first \"yarn dev\" \"cypress open --env playground=local\"", + "test:types": "tsc -b" }, "keywords": [ "react", @@ -21,11 +23,13 @@ "license": "ISC", "devDependencies": { "@meilisearch/instant-meilisearch": "*", + "@types/react": "^19.0.8", + "@types/react-dom": "^19.0.3", "instantsearch.css": "^8.5.1", - "react": "^18.3.1", - "react-dom": "^18.3.1", + "react": "^19.0.0", + "react-dom": "^19.0.0", "@vitejs/plugin-react": "^4.3.4", - "react-instantsearch": "^7.15.0", - "react-router-dom": "^6.28.2" + "react-instantsearch": "^7.15.3", + "react-router-dom": "^7.1.5" } } diff --git a/playgrounds/local-react/src/App.jsx b/playgrounds/local-react/src/App.tsx similarity index 100% rename from playgrounds/local-react/src/App.jsx rename to playgrounds/local-react/src/App.tsx diff --git a/playgrounds/local-react/src/components/MultiIndex.jsx b/playgrounds/local-react/src/components/MultiIndex.tsx similarity index 91% rename from playgrounds/local-react/src/components/MultiIndex.jsx rename to playgrounds/local-react/src/components/MultiIndex.tsx index 19239d50..25c14f7e 100644 --- a/playgrounds/local-react/src/components/MultiIndex.jsx +++ b/playgrounds/local-react/src/components/MultiIndex.tsx @@ -10,6 +10,7 @@ import { Hits, } from 'react-instantsearch' import { instantMeiliSearch } from '@meilisearch/instant-meilisearch' +import type { Hit } from 'algoliasearch' const { searchClient } = instantMeiliSearch( 'http://localhost:7700', @@ -21,7 +22,7 @@ const { searchClient } = instantMeiliSearch( } ) -const Hit = ({ hit }) => { +const HitComponent = ({ hit }: { hit: Hit }) => { return (
@@ -50,7 +51,7 @@ const MultiIndex = () => (
- +
@@ -67,7 +68,7 @@ const MultiIndex = () => (
- +
diff --git a/playgrounds/local-react/src/components/SingleIndex.jsx b/playgrounds/local-react/src/components/SingleIndex.tsx similarity index 86% rename from playgrounds/local-react/src/components/SingleIndex.jsx rename to playgrounds/local-react/src/components/SingleIndex.tsx index 20509fda..639ade01 100644 --- a/playgrounds/local-react/src/components/SingleIndex.jsx +++ b/playgrounds/local-react/src/components/SingleIndex.tsx @@ -12,6 +12,7 @@ import { Snippet, } from 'react-instantsearch' import { instantMeiliSearch } from '@meilisearch/instant-meilisearch' +import type { Hit } from 'algoliasearch' const { searchClient } = instantMeiliSearch( 'http://localhost:7700', @@ -36,6 +37,7 @@ const SingleIndex = () => (
+ {/* TODO: https://www.algolia.com/doc/guides/building-search-ui/upgrade-guides/react/#replace-defaultrefinement-with-initialuistate-on-instantsearch */} (
- +
) -const Hit = ({ hit }) => { +const HitComponent = ({ hit }: { hit: Hit }) => { return (
@@ -81,7 +83,7 @@ const Hit = ({ hit }) => {
- {hit.name} + {hit.name}
diff --git a/playgrounds/local-react/src/components/SingleMovieIndex.jsx b/playgrounds/local-react/src/components/SingleMovieIndex.tsx similarity index 90% rename from playgrounds/local-react/src/components/SingleMovieIndex.jsx rename to playgrounds/local-react/src/components/SingleMovieIndex.tsx index 653464b2..145104c8 100644 --- a/playgrounds/local-react/src/components/SingleMovieIndex.jsx +++ b/playgrounds/local-react/src/components/SingleMovieIndex.tsx @@ -9,6 +9,7 @@ import { RefinementList, } from 'react-instantsearch' import { instantMeiliSearch } from '@meilisearch/instant-meilisearch' +import type { Hit } from 'algoliasearch' const { searchClient } = instantMeiliSearch( 'http://localhost:7700', @@ -34,13 +35,13 @@ const SingleIndex = () => (
- +
) -const Hit = ({ hit }) => { +const HitComponent = ({ hit }: { hit: Hit }) => { return (
diff --git a/playgrounds/local-react/src/index.jsx b/playgrounds/local-react/src/index.tsx similarity index 83% rename from playgrounds/local-react/src/index.jsx rename to playgrounds/local-react/src/index.tsx index 1b16ac74..631172f6 100644 --- a/playgrounds/local-react/src/index.jsx +++ b/playgrounds/local-react/src/index.tsx @@ -4,7 +4,7 @@ import { BrowserRouter } from 'react-router-dom' import './index.css' import App from './App' -createRoot(document.getElementById('app')).render( +createRoot(document.getElementById('app')!).render( diff --git a/playgrounds/local-react/src/vite-env.d.ts b/playgrounds/local-react/src/vite-env.d.ts new file mode 100644 index 00000000..11f02fe2 --- /dev/null +++ b/playgrounds/local-react/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/playgrounds/local-react/tsconfig.app.json b/playgrounds/local-react/tsconfig.app.json new file mode 100644 index 00000000..dfc691d4 --- /dev/null +++ b/playgrounds/local-react/tsconfig.app.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", + "target": "ES2020", + "useDefineForClassFields": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + "jsx": "react-jsx", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedSideEffectImports": true + }, + "include": ["src"] +} diff --git a/playgrounds/local-react/tsconfig.json b/playgrounds/local-react/tsconfig.json new file mode 100644 index 00000000..1ffef600 --- /dev/null +++ b/playgrounds/local-react/tsconfig.json @@ -0,0 +1,7 @@ +{ + "files": [], + "references": [ + { "path": "./tsconfig.app.json" }, + { "path": "./tsconfig.node.json" } + ] +} diff --git a/playgrounds/local-react/tsconfig.node.json b/playgrounds/local-react/tsconfig.node.json new file mode 100644 index 00000000..ff0dc7df --- /dev/null +++ b/playgrounds/local-react/tsconfig.node.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", + "target": "ES2022", + "lib": ["ES2023"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedSideEffectImports": true + }, + "include": ["vite.config.ts"] +} diff --git a/playgrounds/local-react/vite.config.ts b/playgrounds/local-react/vite.config.ts index 4d622e8c..8e054e3a 100644 --- a/playgrounds/local-react/vite.config.ts +++ b/playgrounds/local-react/vite.config.ts @@ -1,9 +1,8 @@ -/* eslint-disable @typescript-eslint/no-require-imports */ -const { defineConfig } = require('vite') -const react = require('@vitejs/plugin-react') +import { defineConfig } from 'vite' +import react from '@vitejs/plugin-react' // https://vite.dev/config/ -module.exports = defineConfig({ +export default defineConfig({ server: { port: 5174, strictPort: true }, plugins: [react()], }) diff --git a/playgrounds/react/index.html b/playgrounds/react/index.html index 3251ccf8..3bce1cbb 100644 --- a/playgrounds/react/index.html +++ b/playgrounds/react/index.html @@ -9,6 +9,6 @@
- + diff --git a/playgrounds/react/package.json b/playgrounds/react/package.json index b4878bad..42569168 100644 --- a/playgrounds/react/package.json +++ b/playgrounds/react/package.json @@ -5,7 +5,8 @@ "description": "React playground for instant-meilisearch", "type": "module", "scripts": { - "dev": "vite" + "dev": "vite", + "test:types": "tsc -b" }, "keywords": [ "react", @@ -17,9 +18,12 @@ "author": "", "license": "ISC", "devDependencies": { - "react": "^18.3.1", - "react-dom": "^18.3.1", - "react-instantsearch": "^7.15.0", + "@types/react": "^19.0.8", + "@types/react-dom": "^19.0.3", + "react": "^19.0.0", + "react-dom": "^19.0.0", + "@vitejs/plugin-react": "^4.3.4", + "react-instantsearch": "^7.15.3", "@meilisearch/instant-meilisearch": "*" } -} \ No newline at end of file +} diff --git a/playgrounds/react/src/App.jsx b/playgrounds/react/src/App.tsx similarity index 89% rename from playgrounds/react/src/App.jsx rename to playgrounds/react/src/App.tsx index e7244c69..629b48ef 100644 --- a/playgrounds/react/src/App.jsx +++ b/playgrounds/react/src/App.tsx @@ -11,6 +11,7 @@ import { SortBy, Snippet, } from 'react-instantsearch' +import type { Hit } from 'algoliasearch' import './App.css' import { instantMeiliSearch } from '@meilisearch/instant-meilisearch' @@ -40,6 +41,7 @@ const App = () => (
+ {/* TODO: https://www.algolia.com/doc/guides/building-search-ui/upgrade-guides/react/#replace-defaultrefinement-with-initialuistate-on-instantsearch */} (
) -const Hit = ({ hit }) => { +const Hit = ({ hit }: { hit: Hit }) => { return (
@@ -85,7 +87,7 @@ const Hit = ({ hit }) => {
- {hit.name} + {hit.name}
diff --git a/playgrounds/react/src/index.jsx b/playgrounds/react/src/index.tsx similarity index 76% rename from playgrounds/react/src/index.jsx rename to playgrounds/react/src/index.tsx index b0eac1a3..5a38342b 100644 --- a/playgrounds/react/src/index.jsx +++ b/playgrounds/react/src/index.tsx @@ -3,7 +3,7 @@ import { createRoot } from 'react-dom/client' import './index.css' import App from './App' -createRoot(document.getElementById('app')).render( +createRoot(document.getElementById('app')!).render( diff --git a/playgrounds/react/src/vite-env.d.ts b/playgrounds/react/src/vite-env.d.ts new file mode 100644 index 00000000..11f02fe2 --- /dev/null +++ b/playgrounds/react/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/playgrounds/react/tsconfig.app.json b/playgrounds/react/tsconfig.app.json new file mode 100644 index 00000000..dfc691d4 --- /dev/null +++ b/playgrounds/react/tsconfig.app.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", + "target": "ES2020", + "useDefineForClassFields": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + "jsx": "react-jsx", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedSideEffectImports": true + }, + "include": ["src"] +} diff --git a/playgrounds/react/tsconfig.json b/playgrounds/react/tsconfig.json new file mode 100644 index 00000000..1ffef600 --- /dev/null +++ b/playgrounds/react/tsconfig.json @@ -0,0 +1,7 @@ +{ + "files": [], + "references": [ + { "path": "./tsconfig.app.json" }, + { "path": "./tsconfig.node.json" } + ] +} diff --git a/playgrounds/react/tsconfig.node.json b/playgrounds/react/tsconfig.node.json new file mode 100644 index 00000000..ff0dc7df --- /dev/null +++ b/playgrounds/react/tsconfig.node.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", + "target": "ES2022", + "lib": ["ES2023"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedSideEffectImports": true + }, + "include": ["vite.config.ts"] +} diff --git a/playgrounds/vue3/index.html b/playgrounds/vue3/index.html index 8388c4bb..5bbf410e 100644 --- a/playgrounds/vue3/index.html +++ b/playgrounds/vue3/index.html @@ -2,12 +2,11 @@ - Vite + Vue
- + diff --git a/playgrounds/vue3/package.json b/playgrounds/vue3/package.json index 93b2ba3c..082f689a 100644 --- a/playgrounds/vue3/package.json +++ b/playgrounds/vue3/package.json @@ -5,13 +5,16 @@ "type": "module", "scripts": { "dev": "vite", - "preview": "vite preview" + "preview": "vite preview", + "test:types": "vue-tsc -b" }, "devDependencies": { - "vue-instantsearch": "^4.10.8", + "vue-instantsearch": "^4.20.4", "@meilisearch/instant-meilisearch": "*", "vue": "^3.5.13", + "@vue/tsconfig": "^0.7.0", "instantsearch.css": "^8.5.1", - "@vitejs/plugin-vue": "^5.2.1" + "@vitejs/plugin-vue": "^5.2.1", + "vue-tsc": "^2.2.0" } } diff --git a/playgrounds/vue3/src/App.vue b/playgrounds/vue3/src/App.vue index 00e87ed2..232a33f3 100644 --- a/playgrounds/vue3/src/App.vue +++ b/playgrounds/vue3/src/App.vue @@ -1,3 +1,13 @@ + + -