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

`algoliasearch` is not callable when `moduleResolution` is `Node16`

Open northen-mindset opened this issue 3 years ago • 3 comments

The project is written in plain JavaScript for Node v16 in the ES Modules format (type: module in package.json).

TypeScript is used as a type checking tool built into the VS Code editor. No transpilation takes place. moduleResolution compiler option in tsconfig.json is set to Node16 according to the documentation. Changing this option to node eliminates the error.

Minimal reproducible example: https://gist.github.com/anantakrishna/97250b7726b1d3b7640872f24d6cd5d3

Error: image

Note: the code runs properly, the error is affecting only the type checking (intellisense in the editor).

northen-mindset avatar Dec 09 '22 17:12 northen-mindset

I had the same error but I just manually typed the default export:

import algoliasearch, { AlgoliaSearchOptions, SearchClient } from "algoliasearch";

const algolia = algoliasearch as unknown as (
  appId: string,
  apiKey: string,
  options?: AlgoliaSearchOptions,
) => SearchClient;

// All good 
const agClient = algolia(...);

I know it's not a good solution but I'm not sure what causes this.

olyop avatar Dec 25 '22 23:12 olyop

👋 Got the same issue here (even when using the lite version algoliasearch/lite) It seems that the type is wrongly mapped to the default export.

If I remap the default export type it works:

import algoliasearch from "algoliasearch"

// Don't work: 'This expression is not callable.'
const agClient = algoliasearch(...)

// All good
const agClient = (algoliasearch as unknown as (typeof algoliasearch)["default"])(...)

CPatchane avatar May 30 '23 14:05 CPatchane

https://arethetypeswrong.github.io/?p=algoliasearch%404.17.1 This tool confirms that there are issues with types and exports: image

northen-mindset avatar Jun 05 '23 13:06 northen-mindset