algoliasearch-client-javascript icon indicating copy to clipboard operation
algoliasearch-client-javascript copied to clipboard

proposal: re-exports all types in `algoliasearch`

Open nunomaduro opened this issue 5 years ago • 9 comments

Today, types like SearchOptions, or Rule are not exported by the algoliasearch package.

People are actually importing them directly from the modular packages:

import { SearchOptions } from '@algolia/client-search';

Solution: re-exports all types, and types from modular packages, in algoliasearch and configure API Extrator to warn us about non exported types.

nunomaduro avatar Mar 13 '20 16:03 nunomaduro

Yes, we should make sure that you don't need to reach into implementation details to be able to fully use the types (they aren't always inferred if you wrap the client e.g.)

Haroenv avatar Mar 16 '20 08:03 Haroenv

Yes please

bodinsamuel avatar Apr 09 '20 08:04 bodinsamuel

+1, this took me quite a while to work out why I couldn't import things directly from algoiasearch.

pinkfish avatar Sep 11 '20 22:09 pinkfish

Any update to this topic?

wiesson avatar Jun 23 '21 09:06 wiesson

Reopening the pull request, I lost track of it. Thanks @wiesson !

Haroenv avatar Jun 23 '21 11:06 Haroenv

@Haroenv no problem :)

I kind of solved it for now:

import type { RequestOptions } from "@algolia/transporter";
import type { SearchOptions } from "@algolia/client-search";

// hacky attempt to remove readonly
type Mutable<T> = { -readonly [P in keyof T]: T[P] };

(...)

let requestOptions: Partial<RequestOptions & Mutable<SearchOptions>> = {
  hitsPerPage: resultsPerPage,
};

if (page) {
  requestOptions.page = page;
}

if (lat && lng) {
  requestOptions.aroundLatLng = `${lat}, ${lng}`;
  requestOptions.aroundRadius =  radius * 1000;
}

if (boundingBox) {
  requestOptions.insideBoundingBox = [boundingBox];
}

const { hits, nbHits, page, nbPages } = await searchIndex.search(q, requestOptions);

(...)

wiesson avatar Jun 23 '21 11:06 wiesson

This is still an issue, two years later after the first request. The current version of algoliasearch still doesn't have access to types, we need to install several unnecessary packages only for types. Any progress on this?

danielpl10 avatar Jun 13 '22 16:06 danielpl10

Any workaround on this issue?

taprile314 avatar Jan 30 '23 22:01 taprile314

All types are exported, but from other packages, like @algolia/client-search, so you can look into the reference and find the import that way.

Haroenv avatar Jan 31 '23 09:01 Haroenv