-
Notifications
You must be signed in to change notification settings - Fork 443
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
Express-JWT 7.x Typescript+Express Typing issues #298
Comments
We didn't want to polute the Request object globally in this release as this also generates some problems. I am not sure what's the definition of your If it is fine for you, you can extend express Request globally in your project. Another option is to cast the object to expressJwt.Request as in |
I actually encountered this same problem. To reproduce it's simple as: import { Router } from "express";
import { expressjwt } from "express-jwt";
Router().use(expressjwt({})); I get this error:
VScode points out: |
hey @Kal-Aster , I think I found the issue. Would you mind to try v8.5 on npm? |
Sure, let me know when it's published |
Hi @jfromaniello could you help publish the v8.5, I believe this will help solve #348 as well. |
Sorry, published! |
I can confirm the new version works well now with express v5, thank you @jfromaniello ! 😃 Tested on
|
We have some issue with this gh repo internally. I will push the changes soon here |
Description
I have followed the type overriding to integrate
express-jwt
andjwks-rsa
but the Typescript Express instructions do not work for me.When I use the provided
Request
type fromexpress-jwt
, I receive the following error from the Typescript compiler:Reproduction
I suspect it is due to the difference in how we attach express-jwt to our endpoints. As we apply it to nearly all endpoints in our application if auth is enabled by the user, we placed it in an express
use
function to be executed on all of our/v1/
endpoints. The complaint happens in a sub-Express object that has been converted, in this case aPOST
endpoint on/v1/db/export
.I expect that the
req
variable is still being mutated correctly in v7.x, but the type is getting erased and returned back to the standardexpress.Request
type. The@types/express-jwt
package for 6.x simply mutates the global type space for Express adding an interface also namedRequest
that contains an optionaluser
property of an opaqueUser
interface type.This may be a solution here, or it may be too heavy-handed for you, but I wanted to bring it up if you can't find a proper solution to the apparent type erasure problem.
Environment
[email protected]
Node v16.15.0
,Express v4.18.1
,Typescript v4.7.3
The text was updated successfully, but these errors were encountered: