Typescript


TypeScript

To allow for index names auto-completion and search results typings, you may define your indices expected results by extending the AlgoliaIndices interface as follows:

// types.d.tsimport '@nuxtjs/algolia'declare module '@nuxtjs/algolia' {  interface AlgoliaIndices {    someIndex: {      foo: string;      bar: number;    }  }}

You may then use your Algolia indices and enjoy typed search hits 🔥

<script lang="ts" setup>const { result, search } = useAlgoliaSearch('someIndex') // Auto-completion for index namesawait search({ query: 'test' }) // @ts-expect-error bar should be a numberresult.value.hits[0].bar = '1'</script>