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

18next-http-middleware in fastify #39

Open
Rafael-006 opened this issue May 31, 2021 · 4 comments
Open

18next-http-middleware in fastify #39

Rafael-006 opened this issue May 31, 2021 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@Rafael-006
Copy link

🐛 Bug Report

I am using this middleware in fastify application with typescript.

When i do compilation using tsc for my application, the type definition of 18next-http-middleware in node_modules throws error as mentioned below,

node_modules/i18next-http-middleware/index.d.ts:9:8 - error TS2307: Cannot find module 'express-serve-static-core' or its corresponding type declarations.

9 } from "express-serve-static-core";

Expected behavior

I've registered this middleware in fastify and typescript configuration are done which includes node_modules to the outDir.

import i18next from 'i18next';
import Backend from 'i18next-fs-backend';
import middleware from 'i18next-http-middleware';
import fastify from 'fastify';

i18next
  .use(Backend)
  .use(middleware.LanguageDetector)
  .init({
    fallbackLng: 'en',
    backend: {
      loadPath: './locales/{{lng}}/translation.json'
    }
  });

fastify.register(middleware.plugin, {
    i18next
  });

fastify();

When i run tsc, expected the compilation to run successfully and output the js files in outDir.

Your Environment

  • runtime version: node v14.17.0
  • i18next version: 20.3.0
  • i18next-fs-backend: 1.1.1
  • i18next-http-middleware: 3.1.3
  • os: Ubuntu 20.04.2
@adrai adrai added the help wanted Extra attention is needed label May 31, 2021
@adrai
Copy link
Member

adrai commented May 31, 2021

Not maintaining TypeScript myself, fastify was probably not respected when #30 was introduced. Can you have a look at it @fominua?

@fominua
Copy link
Contributor

fominua commented Jun 1, 2021

Hey!

Haven't worked with fastify before, I need some time to get familiar with this and remember the changes in this merge.

@g7fernandes
Copy link

@fominua @Rafael-006, did you find a solution?

I'm having typing issues in this same snippet.

No overload matches this call.
  Overload 1 of 3, '(plugin: FastifyPluginCallback<HandleOptions & { i18next?: i18n | undefined; }, Server>, opts?: FastifyRegisterOptions<HandleOptions & { ...; }> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type '(instance: any, options: HandleOptions & { i18next?: i18n | undefined; }, next: NextFunction) => Handler' is not assignable to parameter of type 'FastifyPluginCallback<HandleOptions & { i18next?: i18n | undefined; }, Server>'.
      Types of parameters 'next' and 'done' are incompatible.
        Type '(err?: Error | undefined) => void' is not assignable to type 'NextFunction'.
          Types of parameters 'err' and 'deferToNext' are incompatible.
            Type 'string' is not assignable to type 'Error'.
  Overload 2 of 3, '(plugin: FastifyPluginAsync<HandleOptions & { i18next?: i18n | undefined; }, Server>, opts?: FastifyRegisterOptions<HandleOptions & { ...; }> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type '(instance: any, options: HandleOptions & { i18next?: i18n | undefined; }, next: NextFunction) => Handler' is not assignable to parameter of type 'FastifyPluginAsync<HandleOptions & { i18next?: i18n | undefined; }, Server>'.
  Overload 3 of 3, '(plugin: FastifyPluginCallback<HandleOptions & { i18next?: i18n | undefined; }, Server> | FastifyPluginAsync<HandleOptions & { ...; }, Server> | Promise<...> | Promise<...>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type '(instance: any, options: HandleOptions & { i18next?: i18n | undefined; }, next: NextFunction) => Handler' is not assignable to parameter of type 'FastifyPluginCallback<HandleOptions & { i18next?: i18n | undefined; }, Server> | FastifyPluginAsync<HandleOptions & { ...; }, Server> | Promise<...> | Promise<...>'.
      Type '(instance: any, options: HandleOptions & { i18next?: i18n | undefined; }, next: NextFunction) => Handler' is not assignable to type 'FastifyPluginCallback<HandleOptions & { i18next?: i18n | undefined; }, Server>'.

@productdevbook
Copy link

@g7fernandes
same problem this fixed ?

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

5 participants