jquense / yup

Dead simple Object schema validation
MIT License
22.72k stars 925 forks source link

`number().oneOf` emits wrong type #2230

Open zumm opened 2 months ago

zumm commented 2 months ago

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):