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

number().oneOf emits wrong type #2230

Open
zumm opened this issue Jul 12, 2024 · 1 comment
Open

number().oneOf emits wrong type #2230

zumm opened this issue Jul 12, 2024 · 1 comment

Comments

@zumm
Copy link

zumm commented Jul 12, 2024

Describe the bug
oneOf method on number schema emits type number instead of union of literals. Though if schema is string then emitted type is perfectly correct.

To Reproduce

import { number, string, type InferType } from 'yup';

const NumberOneOfSchema = number().oneOf([1, 2, 3]).required();
type NumberOneOf = InferType<typeof NumberOneOfSchema>; // number

const StringOneOfSchema = string().oneOf(['1', '2', '3']).required();
type StringOneOf = InferType<typeof StringOneOfSchema>; // '1' | '2' | '3'

Expected behavior
oneOf's emmited type should be union of literals. E.g. type of NumberOneOf in example above should be 1 | 2 | 3.

Platform (please complete the following information):

  • Version 1.4.0
@fomalhautb
Copy link

Boolean has the same problem I think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants