Using TypeScript with Typesense JS Library
TLDR michtio asked how to use TypeScript with Typesense JS library, and Ross provided detailed example code.
1
Jul 20, 2022 (15 months ago)
michtio
02:05 PMQuick question for the Typesense JS library, are there docs somewhere that describe how to use TypeScript within it?
e.g. if I want to do something like:
import Typesense from 'typesense'```
export const useTypesenseClient = (protocol = 'https', port = 443): SearchClient => {``
Where it will say
SearchClient` not found, which is kind of obvious, but I find no information whatsoever on how to import types / which types / etc … ?Ross
02:33 PMimport { Client } from 'typesense';
import {
SearchParams,
SearchOptions,
SearchResponse
} from 'typesense/lib/Typesense/Documents';
import {
MultiSearchRequestSchema,
MultiSearchRequestsSchema,
MultiSearchResponse
} from 'typesense/lib/Typesense/MultiSearch';
import { CollectionSchema } from 'typesense/lib/Typesense/Collection';
1
michtio
03:52 PMTypesense
Indexed 2776 threads (79% resolved)
Similar Threads
Typesense-JS Client Types Importation Problem.
Stefan had problems importing types from typesense-JS, causing compiler slowdowns. Jason and Damian provided guidance and agreed to export necessary types from Typesense.ts, improving import speed and reducing compiler checks.
Issues with TypesenseClient Import in Typescript
David struggled to find correct import syntax for TypesenseClient in TypeScript, and Jason clarified the proper usage. The documentation for the import will now be updated.
Typescript Support and Import Issues with Typesense
Ahmad faced trouble with Typesense support for Typescript. Jason assisted by suggesting checks and solutions. Phil suggested modifying the import statement. Ultimately, the issue was resolved with a change from Jason in version `v1.1.2`.