Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: re-exports all types in algoliasearch #1080

Open
nunomaduro opened this issue Mar 13, 2020 · 9 comments · May be fixed by #1284
Open

proposal: re-exports all types in algoliasearch #1080

nunomaduro opened this issue Mar 13, 2020 · 9 comments · May be fixed by #1284
Labels
investigate on hold v5 Introduced in the generated API clients: https://github.com/algolia/api-clients-automation

Comments

@nunomaduro
Copy link
Contributor

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.

@Haroenv
Copy link
Contributor

Haroenv commented Mar 16, 2020

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.)

@bodinsamuel
Copy link
Contributor

Yes please

@pinkfish
Copy link

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

@wiesson
Copy link

wiesson commented Jun 23, 2021

Any update to this topic?

@Haroenv Haroenv linked a pull request Jun 23, 2021 that will close this issue
@Haroenv
Copy link
Contributor

Haroenv commented Jun 23, 2021

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

@wiesson
Copy link

wiesson commented Jun 23, 2021

@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);

(...)

@danielpl10
Copy link

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?

@Kraloz
Copy link

Kraloz commented Jan 30, 2023

Any workaround on this issue?

@Haroenv
Copy link
Contributor

Haroenv commented Jan 31, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate on hold v5 Introduced in the generated API clients: https://github.com/algolia/api-clients-automation
Projects
None yet
8 participants