joi-to-typescript
joi-to-typescript copied to clipboard
Adding allow(0) to number().positive() goes down to 0 instead of number
Hi I'm having similar problem as described here: https://github.com/mrjono1/joi-to-typescript/issues/244 and that is according to this change https://github.com/mrjono1/joi-to-typescript/issues/206 should be working differently.
As title says: Adding allow(0) to number().positive() goes down to 0 instead of number.
In general based on the issue: https://github.com/mrjono1/joi-to-typescript/issues/206 this behaviour should only happen when I would specify valid(0)
or only(0)
.
To Reproduce Steps to reproduce the behavior:
import Joi from "joi";
export const JobSchema = Joi.object({
uptime: Joi.number().positive().allow(0),
}).meta({ className: 'Job' });
Expected behavior Generated type should be:
export interface Job {
uptime?: number | 0; // or it can be just number
}
Actual behavior
export interface Job {
uptime?: 0;
}
For now workaround I figured could be to add .meta
e.g.:
export const JobSchema = Joi.object({
uptime: Joi.number().positive().allow(0).meta({ className: 'number' }),
}).meta({ className: 'Job' });
// results to
export interface Job {
uptime?: number | 0;
}
Allow is working almost the same as valid this should be fixed