Browsing an index in TypeScript

I’m trying to write code to browse an index, specifically using the browseAll method. I tested what I want to do in plain JavaScript using the Browse an index (recommended way) example. Now I want to take my code and put it into a TypeScript class along with some other code. I’m hung up on how to convert the browser.on event hooks.

It looks like, at least per the type files, that browseAll is returning Promise<Response>, causing an error because on is not defined for Promise. When I examine the JS version in the debugger, the type of browser is actually being reported as IndexBrowser. As far as I can tell, IndexBrowser does not exist in the type definitions. It looks like the generated JS is the same as the example (formatting notwithstanding), so can I just suppress the errors and go on? Is this just a matter of the type definition not being correct?

My algoliasearch package version is 3.30.0, and my @types/algoliasearch package version is 3.27.8.

You’re right! this actually indeed seems like an error in the typings, made because browse does return a promise, and browseAll returning an IndexBrowser.

Do you want to create a PR to DefinitelyTyped to fix that?

I just made a PR to DefinitelyTyped to fix this