Skip to content
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

Adding allow(0) to number().positive() goes down to 0 instead of number #446

Open
Cheprer opened this issue Apr 8, 2024 · 2 comments
Open
Labels
bug Something isn't working

Comments

@Cheprer
Copy link

Cheprer commented Apr 8, 2024

Hi I'm having similar problem as described here: #244 and that is according to this change #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: #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;
}
@Cheprer
Copy link
Author

Cheprer commented Apr 8, 2024

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;
}

@mrjono1 mrjono1 added the bug Something isn't working label May 26, 2024
@mrjono1
Copy link
Owner

mrjono1 commented May 26, 2024

Allow is working almost the same as valid this should be fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants