Typescript Support and Import Issues with Typesense
TLDR 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
.
Dec 22, 2021 (21 months ago)
Ahmad
09:54 PMJason
09:55 PMAhmad
09:57 PMimport Typesense from "typesense";
export class TypesenseDB {
client;
constructor() {
console.log(Typesense);
this.client = new Typesense.Client({
nodes: [
{
host: "/////////",
port: 443,
protocol: "https",
},
],
apiKey: "////////",
connectionTimeoutSeconds: 2,
});
}
}
Ahmad
09:58 PMTypesense
as undefined
.Jason
10:00 PMAhmad
10:01 PM@types/typesense
.Jason
10:02 PMJason
10:02 PM@babel/runtime
thoughJason
10:03 PMAhmad
10:03 PM"typesense": "^1.0.2",
version is also fine.
Jason
10:03 PMAhmad
10:04 PMAhmad
10:11 PMTypeError: Cannot read properties of undefined (reading 'Client')
Jason
10:12 PMAhmad
10:19 PMJason
10:19 PMAhmad
10:25 PMAhmad
10:25 PMusing ts-node ver. 9.1.1, typescript ver. 4.5.4
Ahmad
10:26 PMDec 23, 2021 (21 months ago)
Phil
01:26 AMI think it should be either
import * as Typesense from 'typesense'
or
import { Client } from 'typesense'
Rohit
08:47 AMimport {Client as TypesenseClient} from "typesense";
import * as config from 'config';
export class SearchService {
client: TypesenseClient;
constructor() {
if (!config.has('typesense')) {
return;
}
this.client = new TypesenseClient({
'nodes': [
{
'host': config.get('typesense.host'),
'port': config.get('typesense.port'),
'protocol': config.get('typesense.protocol')
}],
'apiKey': config.get('typesense.apiKey'),
'numRetries': config.get('typesense.numRetries'), // A total of 4 tries (1 original try + 3 retries)
'connectionTimeoutSeconds': config.get('typesense.connectionTimeoutSeconds'),
'logLevel': config.get('typesense.logLevel'),
'retryIntervalSeconds': 2,
'timeoutSeconds': 4,
});
}
}
Rohit
08:47 AMDec 24, 2021 (21 months ago)
Jason
12:01 AMimport Typesense from 'typesense'
way of importing Typesense "broke" recently after we removed a default export. I've pushed out a fix in v1.1.2
. Could you upgrade to this version and try again?More context here: https://github.com/typesense/typesense-js/issues/94#issuecomment-1000569392
Jason
12:01 AMTypesense
Indexed 2764 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.
Troubleshooting TypeScript Error with Typesense
GM experienced an error with Typesense in TypeScript, requiring help to correct the issues. Jason helped propose solutions and adjustments to the code. Ultimately, they were able to resolve the errors and successfully implement a search function.


Troubleshooting Typesense Errors in NestJS Project
Iulian is experiencing Typesense errors in a NestJS project. Kishore Nallan and Jason provide advice, suggesting try-catch and looking at code snippets respectively.

Phrase Match Problem in Typesense Version 0.24.0rcn25
Robert was unsure about correct phrase match usage in Typesense. After providing Kishore Nallan with necessary data, Kishore Nallan was able to replicate the issue. Robert shared a Github link for further tracking, where Kishore Nallan responded later.
Query Parameters Issue in Using Typesense with Flutter
Shane was having issues with query parameters when using the Typesense package in a Flutter app. Kishore Nallan advised to avoid using the preset parameter, and the issue was resolved when Shane directly specified 'query_by'. Kishore Nallan will investigate the likely issue with the Flutter client.