i18next-http-middleware
i18next-http-middleware copied to clipboard
18next-http-middleware in fastify
🐛 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
Not maintaining TypeScript myself, fastify was probably not respected when #30 was introduced. Can you have a look at it @fominua?
Hey!
Haven't worked with fastify before, I need some time to get familiar with this and remember the changes in this merge.
@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>'.
@g7fernandes same problem this fixed ?