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

TypeScript Guide #1079

Closed
shadow1349 opened this issue Mar 13, 2020 · 4 comments
Closed

TypeScript Guide #1079

shadow1349 opened this issue Mar 13, 2020 · 4 comments

Comments

@shadow1349
Copy link

I'm currently trying to migrate from using @types/algoliasearch to using algoliasearch@4.1.0 (from 3.35.1).

I was using a generic class to handle all interactions with algolia in my project and to do that I needed to access the QueryParameters interface. Here is an example

import algoliasearch, { SearchIndex } from 'algoliasearch';

export class AlgoliaSearch {
  private index: SearchIndex;

  constructor(index: SearchIndex) {
    this.index = index;
  }

  // Cannot access RequestOptions or SearchOptions
  search<T>(params: RequestOptions & SearchOptions) {
    return this.index.search<T>(params);
  }
}

Only after looking through your type definitions did I realize that I had to install 2 different packages: @algolia/cient-search and @algolia/transporter for the right types.

Is there any way you guys can put up a TypeScript guide?

Thanks!

@shadow1349
Copy link
Author

I would also be happy to spend some time to help contribute to the guide as well, there are just a lot of gotchas when using algoliaSearch >= 4.0 with TypeScript that I have been running into

@nunomaduro
Copy link
Contributor

Exporting all types from the algoliasearch would fix your problem? #1080

@shadow1349
Copy link
Author

RequestOptions is only available as part of the @algolia/transporter package as well as SearchOptions is only available from @algolia/client-search. When I tried to export those types from algoliasearch they aren't directly exported so they can't be found

@nunomaduro
Copy link
Contributor

@shadow1349 Got! So indeed, if we re-export all the types from algoliasearch, that would fix your problem. So let's consider this issue, a duplicated of #1080.

Maybe you can help us there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants