jquense / yup

Dead simple Object schema validation
MIT License
22.83k stars 932 forks source link

Schema sets property to optional / with questionmark #1939

Closed Edelf closed 1 year ago

Edelf commented 1 year ago

Given the following interface: interface ChildInterface { myProperty: string | null | undefined; }

And the following Schema definition: const schemaChild: yup.ObjectSchema<ChildInterface> = yup.object({ myProperty: yup.string().notRequired() });

The result of schemaChild is (note the questionmark '?' on the property): type ChildType { myProperty?: string | null | undefined; }

This is causing me issues when reusing the ObjectSchema in other Schemas.

Example: https://codesandbox.io/s/romantic-ganguly-muvkpz?file=/src/index.ts

jquense commented 1 year ago

The type yup produces is accurate, the properties may be missing, not just undefined. It's pretty difficult to make the schema produce one or the other dynamically