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

algoliasearch is not callable when moduleResolution is Node16 #1431

Open
anantakrishna opened this issue Dec 9, 2022 · 3 comments
Open

algoliasearch is not callable when moduleResolution is Node16 #1431

anantakrishna opened this issue Dec 9, 2022 · 3 comments

Comments

@anantakrishna
Copy link

anantakrishna commented Dec 9, 2022

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

@olyop
Copy link

olyop commented Dec 25, 2022

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.

@CPatchane
Copy link

👋 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"])(...)

@anantakrishna
Copy link
Author

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

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

3 participants