-
Notifications
You must be signed in to change notification settings - Fork 21
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
Can I use this with number()? #30
Comments
@danielbrauer could you you |
@danielbrauer in case you're curious what the patch is - check this commit. I tested locally using your example and by changing my |
Thanks for addressing this! With the new version, I get exactly one compilation error:
|
Running into a compilation error in express-joi-validation evanshortiss/express-joi-validation#30 (comment)
@danielbrauer can you update to Joi v16 and Joi types v16? AFAICT that'll resolve the new issue, i.e |
Thanks. I tried that, but it breaks Is there any alternative to avoid redundant type definitions? |
Unfortunately it appears not with Joi v16. One potential solution is that the 3.x release line of this module could support Joi v15. I think it should be possible to merge the current master branch of this repo into the 3.x branch and set the Joi dev/peer deps in package.json to v15. This could achieve extractType compatibility while a Joi v16 solution is being figured out. I don't have much time to test that in the next week of so, but perhaps you could fork the module and give it a shot? |
Thanks, I tried using 3.x with current master (which merged automatically) and the lowered Joi peer dependency. However, the compilation error persists. Was there something in 3.x or master which should address this? https://github.com/danielbrauer/express-joi-validation/tree/3.x |
@danielbrauer, works for me. Did you I started with a fresh project:
Here's the index.ts I used: import * as Joi from '@hapi/joi'
import express from 'express'
import {
ContainerTypes,
ValidatedRequest,
ValidatedRequestSchema,
createValidator
} from 'express-joi-validation'
const app = express()
const validator = createValidator()
const querySchema = Joi.object({
name: Joi.number().required()
})
interface HelloRequestSchema extends ValidatedRequestSchema {
[ContainerTypes.Query]: {
name: number
}
}
app.get(
'/hello',
validator.query(querySchema),
(req: ValidatedRequest<HelloRequestSchema>, res: express.Response) => { // No overload matches this call
res.end(`Hello ${req.query.name}!`)
}
)
app.listen(8080, (err) => {
if (err) throw err
console.log('server is listening on 8080')
}) |
@danielbrauer and the resulting package.json was: {
"name": "joi-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@hapi/joi": "^15.1.1",
"@types/hapi__joi": "^15.0.4",
"express": "^4.17.1",
"express-joi-validation": "github:danielbrauer/express-joi-validation#3.x",
"typescript": "^3.9.7"
},
"devDependencies": {
"@types/express": "^4.17.7"
}
} |
Thanks for looking into this further, and for the detailed setup. It appears that the default tsconfig includes |
Good catch. This one isn't too bad to fix. Here's the fix in mainline 3.x. I think using this might be better: export interface ExpressJoiError extends Joi.ValidationResult<unknown> {
type: ContainerTypes
} If this works could you open a PR against 3.x here and I can create a new 3.x release? EDIT: this works for me, but just want to get a second verification from you @danielbrauer |
Facing the same error when using ContainerTypes.Params with a number parameter in it |
2024 here, same issue as @hqureshi0 unfortunately |
@Sufiane, I don't have much time to maintain this library anymore. If you'd like to open a PR I'd happily release it. I could make some of the folks in this thread maintainers if any of you are willing. |
truth be told I was just doing a code challenge, I tend to not use express anymore I prefer (and would recommend) going with fastify or if you want a framework to go with nest |
This validator looks like what I need, but as soon as I try to put a number in the schema I get horrible errors. Here is reproduction code, just slightly modified version of your type extraction example:
This produces the error:
I am using:
Updated to remove type extraction: the issue happens even without it
The text was updated successfully, but these errors were encountered: