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: @fastify/elasticsearch does not accept older client #895

Open
jatin2-kumar opened this issue Jun 22, 2023 · 3 comments
Open
Labels
help wanted Extra attention is needed

Comments

@jatin2-kumar
Copy link

Hi Team,
I need to use a previous version of the client while registering the fastifyelasticsearch in typescript.
I am doing it like this

import fp from 'fastify-plugin';
import fastifyElasticsearch from '@fastify/elasticsearch';
import { Client } from '@elastic/elasticsearch';

export default fp(async (server) => {
  try {
    await server.register(fastifyElasticsearch, {
      client: new Client({ node: 'http://localhost:9200' }),
    });
  } catch (error) {
    server.log.error(error, 'Failed to initialize Elasticsearch');
    throw error;
  }
});

But it is giving me an error for the new Client :

No overload matches this call.
  Overload 1 of 3, '(plugin: FastifyPluginCallback<FastifyElasticsearchOptions, RawServerDefault, FastifyTypeProviderDefault, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...>): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Type 'Client' is missing the following properties from type 'Client': diagnostic, name, helpers, asyncSearch, and 72 more.
  Overload 2 of 3, '(plugin: FastifyPluginAsync<FastifyElasticsearchOptions, RawServerDefault, FastifyTypeProviderDefault, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...>): FastifyInstance<...> & PromiseLike<...>', gave the following error.Overload 2 of 3, '(plugin: FastifyPluginAsync<FastifyElasticsearchOptions, RawServerDefault, FastifyTypeProviderDefault, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...>): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Type 'import("/node_modules/@elastic/elasticsearch/index").Client' is not assignable to type 'import("/node_modules/@fastify/elasticsearch/node_modules/@elastic/elasticsearch/lib/client").default'.
  Overload 3 of 3, '(plugin: FastifyPluginAsync<FastifyElasticsearchOptions, RawServerDefault, FastifyTypeProviderDefault, FastifyBaseLogger> | FastifyPluginCallback<...> | Promise<...> | Promise<...>, opts?: FastifyRegisterOptions<...>): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Type 'import("/node_modules/@elastic/elasticsearch/index").Client' is not assignable to type 'import("/node_modules/@fastify/elasticsearch/node_modules/@elastic/elasticsearch/lib/client").default'.ts(2769)

Can you help here to solve this issue?

Your Environment

  • node version: v18.15.0
  • fastify version: >=2.0.0
  • "@elastic/elasticsearch": "^5.6.22",
  • "@fastify/elasticsearch": "^3.1.0",
  • os: Mac
@jatin2-kumar jatin2-kumar added the help wanted Extra attention is needed label Jun 22, 2023
@Eomm
Copy link
Member

Eomm commented Jun 22, 2023

The plugin has this version: "@elastic/elasticsearch": "^8.2.1",
https://github.com/fastify/fastify-elasticsearch/blob/master/package.json#L31

I'm not a TS user - can't suggest anything better than adding as any

@Eomm Eomm changed the title Help Typescript: @fastify/elasticsearch does not accept older client Jun 22, 2023
@jatin2-kumar
Copy link
Author

yes, the plugin has this version: "@elastic/elasticsearch": "^8.2.1", but i need to use a old version for client so thats why using the older version.

@Uzlopak
Copy link

Uzlopak commented Jun 22, 2023

I would actually recommend to fork this plugin and patch it correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants