Skip to content

[bug]: TS missing type union? #1611

Closed
Closed

Description

@Rolleander

Description

The type SearchClientNodeHelpers does not seem to be used in the searchclient typing.
As a result, the generateSecuredApiKey method and others are not available in the client typing.

I had to use this workaround:

import { Algoliasearch, algoliasearch, type SearchClientNodeHelpers } from "algoliasearch";

type NodeAlgoliaClient = Algoliasearch & SearchClientNodeHelpers;

let algolia = algoliasearch(appId, apiKey) as NodeAlgoliaClient;
algolia.generateSecuredApiKey({...});

Client

Search

Version

5.55.0

Relevant log output

Activity

  1. shortcuts commented on Jun 23, 2026

    @shortcuts
    Member

    Hey, could you please provide some details about the environment are you running the client on?

    The client exposes builds for different env (browser, node, workers, etc.), and looking at the node bundler chain, it should already provide that type union exposed here https://github.com/algolia/api-clients-automation/blob/d33878eea6915a492e6709e4ebdc52ce4cb458d0/clients/algoliasearch-client-javascript/packages/client-search/builds/node.ts#L3

    on a fresh repository with node 24.15.0, my algoliasearch imports node_modules/algoliasearch/dist/node.d.ts typed Algoliasearch which is a union of SearchClient imported from node_modules/@algolia/client-search/dist/node.d.ts that resolves to the line I've sent above

    I'm wondering if yours doesn't resolve to the browser build, which doesn't union the node helpers type https://github.com/algolia/api-clients-automation/blob/d33878eea6915a492e6709e4ebdc52ce4cb458d0/clients/algoliasearch-client-javascript/packages/client-search/builds/browser.ts#L51

  2. Rolleander commented on Jun 23, 2026

    @Rolleander
    Author

    What details should i look up exactly?

    My repository uses node 24 and has the dependency "algoliasearch": "5.55.0".
    It is a basic node project for cloud functions.
    When i open the type definition with vs-code ( node_modules/algoliasearch/dist/browser.d.ts ) i can see that it looks like this:

    type Algoliasearch = SearchClient & {
        initAbtesting: (initOptions: InitClientOptions & RegionOptions$1) => AbtestingClient;
        initAbtestingV3: (initOptions: InitClientOptions & RegionOptions$2) => AbtestingV3Client;
        initAnalytics: (initOptions: InitClientOptions & RegionOptions$3) => AnalyticsClient;
        initIngestion: (initOptions: InitClientOptions & RegionOptions$4) => IngestionClient;
        initInsights: (initOptions: InitClientOptions & RegionOptions$5) => InsightsClient;
        initMonitoring: (initOptions?: InitClientOptions) => MonitoringClient;
        initPersonalization: (initOptions: InitClientOptions & RegionOptions$6) => PersonalizationClient;
        initQuerySuggestions: (initOptions: InitClientOptions & RegionOptions$7) => QuerySuggestionsClient;
        initRecommend: (initOptions?: InitClientOptions) => RecommendClient;
        saveObjectsWithTransformation: (options: SaveObjectsOptions, requestOptions?: RequestOptions | undefined) => Promise<Array<WatchResponse>>;
        partialUpdateObjectsWithTransformation: (options: PartialUpdateObjectsOptions, requestOptions?: RequestOptions | undefined) => Promise<Array<WatchResponse>>;
        replaceAllObjectsWithTransformation: (options: ReplaceAllObjectsOptions, requestOptions?: RequestOptions | undefined) => Promise<ReplaceAllObjectsWithTransformationResponse>;
    };
  3. shortcuts commented on Jun 23, 2026

    @shortcuts
    Member

    Thanks for your answer

    It is a basic node project for cloud functions.

    This was the information I was looking for! This way we can try to see if the module resolution is appropriate for your runner, here it seems to resolve the browser bundle which I guess isn't correct, I don't know much about cloud functions so we would need to investigate, but I believe it should be similar to the cloudflare workers cc @Fluf22

  4. shortcuts commented on Jun 23, 2026

    @shortcuts
    Member

    Just a hint in case that's as easy as that but make sure your module resolution is set to node, something like https://github.com/getsentry/cloud-run-typescript-template/blob/main/tsconfig.json#L6

  5. Rolleander commented on Jun 23, 2026

    @Rolleander
    Author

    Thank you very much, that was the issue. I had the tsconfig not correctly setup.
    Changing from "module": "commonjs" to "module": "Node16" and "moduleResolution": "node16" fixed it and types are working correctly now for algolia.

  6. shortcuts commented on Jun 23, 2026

    @shortcuts
    Member

    Let's goooooooo enjoy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions