jquense / yup

Dead simple Object schema validation
MIT License
22.93k stars 934 forks source link

Array of object or simple type throws Type error on typescript after update >1.0.0 #2147

Closed VenciNanov closed 11 months ago

VenciNanov commented 11 months ago

Describe the bug Array of custom objects or simple types(string,number etc) throws type error after update to 1.3.2 from 0.32.11

Type 'ObjectSchema<{ items1: any; }, AnyObject, { items1: any; }, "">' is not assignable to type 'ObjectSchema<test1, AnyObject, any, "">'. The types of 'default(...).__outputType' are incompatible between these types. Property 'items1' is missing in type '{ [x: string]: any; }' but required in type '{ items1: string[]; }'.ts(2322)

To Reproduce

type test1 = {
  items1: string[];
};
const validationSchema1: yup.ObjectSchema<test1> = yup.object({
  items1: yup.array().of(yup.string()),
});

image

Expected behavior Its expected to work like before, there is no mentions of breaking changes in the changelog or anything. I guess I'll have to postpone the update for now.

Platform (please complete the following information):

jquense commented 11 months ago

the error is accurate and correct. You are saying that items1 is required in your interface, but the schema default for fields is that they are optional.