-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Update typings to allow req.i18n and req.t without Typescript error. #177
Conversation
published in i18next-express-middleware@1.7.3 |
@jamuhl Just a heads up - ran into a collision with |
@isaachinman @nicolasigot if both agree we could revert this change? |
For some context, I believe that exporting something like this is the most flexible way for a package to support typings - let your users consume the typings however they'd like. |
@nicolasigot would you be able to provide a PR for suggested change? |
Hello @jamuhl , @isaachinman , Thanks for your feedback. I reviewed this case and the way it is exported in next-i18next will force the developper to cast the request object to a specific type each time he wants to access to specific properties or functions. The usual way to do it by extending the express Request object in global is to benefit from typescript declaration merging. So that with the Request type we can access to all extended features of it. I also checked how it is done for other express middleware and I found it the same way (ex: Passport) https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/passport/index.d.ts I do not understand the conflict you have with next-i18next as you should extend it globally as well and from what I see you are adding options in i18n spec and this should be fine to do it globally as well. This is how you were doing before your commit (i18next/next-i18next@294ab6f#diff-d96ec7ae5bb4a0907779f25ed03acb33). So I am not in favor of rolling back this update. Thanks, |
Hi @nicolasigot, thanks for your response. Let me explain a bit further. Middlewares should not modify the global Imagine, for a moment, a project wherein some routers use
Exactly right! That's to be expected, and is how TypeScript works. |
Ah, and if you check the passport typings, you'll find a number of issues relating to typing conflicts with other packages, eg |
so we got an agreement that modifying global scope is nice but leads to even more problems beside all the problems typescript already adds ;) |
Hello,
I missed these attributes in my previous PR. I hope I have all attributes now.
Thanks,
Nicolas