hjkcai / typesafe-joi

A fork of joi that produces typed validation results in TypeScript
MIT License
73 stars 9 forks source link

Enhance Joi.strip() types #24

Closed thomasmikava closed 4 years ago

thomasmikava commented 4 years ago

Here is my proposal of enhancing Joi.strip()

Since strip() is used only for sanitizing purposes, typesafe-joi can handle it just like forbidden(). So the type definitions of strip() and forbidden() can be same. In this case,

const UserSchema = Joi.object({
    firstname: Joi.string().required(),
    lastname: Joi.string().required(),
});
const PostUser = UserSchema.keys({
    lastname: Joi.strip(),
});

generated type from PostUser is be

{
    firstname: string;
    lastname: never;
}

But if we change type definitions of strip and make it behave like forbidden, generated type from PostUser will be

{
    firstname: string;
}

which is more accurate.

P.S. I know that this project is not maintained, but please consider this enhancement. It will only take a mere minute to replace type definitions of strip() with same as forbidden()

Thanks!

hjkcai commented 4 years ago

Could you please help me submit a PR?

hjkcai commented 4 years ago

Released #25 in v2.1.0