{"_path":"/advanced/typescript","_draft":false,"_partial":false,"_empty":false,"title":"Typescript","description":"","excerpt":{"type":"root","children":[{"type":"element","tag":"h2","props":{"id":"typescript"},"children":[{"type":"text","value":"TypeScript"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"To allow for index names auto-completion and search results typings, you may define your indices expected results by extending the "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"AlgoliaIndices"}]},{"type":"text","value":" interface as follows:"}]},{"type":"element","tag":"code","props":{"code":"// types.d.ts\nimport '@nuxtjs/algolia'\n\ndeclare module '@nuxtjs/algolia' {\n interface AlgoliaIndices {\n someIndex: {\n foo: string;\n bar: number;\n }\n }\n}\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"// types.d.ts\nimport '@nuxtjs/algolia'\n\ndeclare module '@nuxtjs/algolia' {\n interface AlgoliaIndices {\n someIndex: {\n foo: string;\n bar: number;\n }\n }\n}\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"You may then use your Algolia indices and enjoy typed search hits 🔥"}]},{"type":"element","tag":"code","props":{"code":"\n","language":"vue"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"\n"}]}]}]}]},"body":{"type":"root","children":[{"type":"element","tag":"h2","props":{"id":"typescript"},"children":[{"type":"text","value":"TypeScript"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"To allow for index names auto-completion and search results typings, you may define your indices expected results by extending the "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"AlgoliaIndices"}]},{"type":"text","value":" interface as follows:"}]},{"type":"element","tag":"code","props":{"code":"// types.d.ts\nimport '@nuxtjs/algolia'\n\ndeclare module '@nuxtjs/algolia' {\n interface AlgoliaIndices {\n someIndex: {\n foo: string;\n bar: number;\n }\n }\n}\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-77f680"},"children":[{"type":"text","value":"// types.d.ts"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-29ed6b"},"children":[{"type":"text","value":"import"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"class":"ct-6ae319"},"children":[{"type":"text","value":"'@nuxtjs/algolia'"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-29ed6b"},"children":[{"type":"text","value":"declare"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"class":"ct-29ed6b"},"children":[{"type":"text","value":"module"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"class":"ct-6ae319"},"children":[{"type":"text","value":"'@nuxtjs/algolia'"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" {"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"class":"ct-29ed6b"},"children":[{"type":"text","value":"interface"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"class":"ct-422741"},"children":[{"type":"text","value":"AlgoliaIndices"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" {"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"class":"ct-113246"},"children":[{"type":"text","value":"someIndex"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":": {"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"class":"ct-113246"},"children":[{"type":"text","value":"foo"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":": "}]},{"type":"element","tag":"span","props":{"class":"ct-422741"},"children":[{"type":"text","value":"string"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":";"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"class":"ct-113246"},"children":[{"type":"text","value":"bar"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":": "}]},{"type":"element","tag":"span","props":{"class":"ct-422741"},"children":[{"type":"text","value":"number"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":";"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" }"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" }"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":"}"}]}]}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"You may then use your Algolia indices and enjoy typed search hits 🔥"}]},{"type":"element","tag":"code","props":{"code":"\n","language":"vue"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":"<"}]},{"type":"element","tag":"span","props":{"class":"ct-113246"},"children":[{"type":"text","value":"script"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"class":"ct-9eb1b3"},"children":[{"type":"text","value":"lang"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":"="}]},{"type":"element","tag":"span","props":{"class":"ct-6ae319"},"children":[{"type":"text","value":"\"ts\""}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"class":"ct-9eb1b3"},"children":[{"type":"text","value":"setup"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":">"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-29ed6b"},"children":[{"type":"text","value":"const"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" { "}]},{"type":"element","tag":"span","props":{"class":"ct-422741"},"children":[{"type":"text","value":"result"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":", "}]},{"type":"element","tag":"span","props":{"class":"ct-422741"},"children":[{"type":"text","value":"search"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" } "}]},{"type":"element","tag":"span","props":{"class":"ct-d4cad0"},"children":[{"type":"text","value":"="}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"class":"ct-722baa"},"children":[{"type":"text","value":"useAlgoliaSearch"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":"("}]},{"type":"element","tag":"span","props":{"class":"ct-6ae319"},"children":[{"type":"text","value":"'someIndex'"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":") "}]},{"type":"element","tag":"span","props":{"class":"ct-77f680"},"children":[{"type":"text","value":"// Auto-completion for index names"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-29ed6b"},"children":[{"type":"text","value":"await"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"class":"ct-722baa"},"children":[{"type":"text","value":"search"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":"({ "}]},{"type":"element","tag":"span","props":{"class":"ct-113246"},"children":[{"type":"text","value":"query"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":": "}]},{"type":"element","tag":"span","props":{"class":"ct-6ae319"},"children":[{"type":"text","value":"'test'"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" }) "}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-77f680"},"children":[{"type":"text","value":"// @ts-expect-error bar should be a number"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-422741"},"children":[{"type":"text","value":"result"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":"."}]},{"type":"element","tag":"span","props":{"class":"ct-422741"},"children":[{"type":"text","value":"value"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":"."}]},{"type":"element","tag":"span","props":{"class":"ct-113246"},"children":[{"type":"text","value":"hits"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":"["}]},{"type":"element","tag":"span","props":{"class":"ct-9eb1b3"},"children":[{"type":"text","value":"0"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":"]."}]},{"type":"element","tag":"span","props":{"class":"ct-113246"},"children":[{"type":"text","value":"bar"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"class":"ct-d4cad0"},"children":[{"type":"text","value":"="}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"class":"ct-6ae319"},"children":[{"type":"text","value":"'1'"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":""}]},{"type":"element","tag":"span","props":{"class":"ct-113246"},"children":[{"type":"text","value":"script"}]},{"type":"element","tag":"span","props":{"class":"ct-cf0dd9"},"children":[{"type":"text","value":">"}]}]}]}]}]},{"type":"element","tag":"style","children":[{"type":"text","value":".ct-722baa{color:#61AFEF}.ct-d4cad0{color:#56B6C2}.ct-9eb1b3{color:#D19A66}.ct-113246{color:#E06C75}.ct-422741{color:#E5C07B}.ct-6ae319{color:#98C379}.ct-cf0dd9{color:#ABB2BF}.ct-29ed6b{color:#C678DD}.ct-77f680{color:#7F848E}"}]}],"toc":{"title":"","searchDepth":2,"depth":2,"links":[{"id":"typescript","depth":2,"text":"TypeScript"}]}},"_type":"markdown","_id":"content:2.advanced:4.typescript.md","_source":"content","_file":"2.advanced/4.typescript.md","_extension":"md"}