You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I implement a dynamic yup schema that validates an IIngredient<T> with a dynamic T?
I've tried it like this:
// Throws a TypeError (see below)exportconstingredientSchemaYup=<Textendsobject>(ingredient: ObjectSchema<T>): ObjectSchema<IIngredient<T>>=>object({grams: number().required(),ingredient: ingredient});// Returns an ObjectSchema<IIngredient<IFlour>, ...>, as expected.constflourIngredientSchemaYup=ingredientSchemaYup(flourSchemaYup);
TypeError:
TS2322: Type 'ObjectSchema<{ grams: number; ingredient: MakeKeysOptional<T>; }, AnyObject, { grams: undefined; ingredient: any; }, "">' is not assignable to type 'ObjectSchema<IIngredient<T>, AnyObject, any, "">'. The types of 'default(...).fields.ingredient' are incompatible between these types. Type 'Reference<unknown> | ISchema<MakeKeysOptional<T>, AnyObject, any, any>' is not assignable to type 'Reference<unknown> | ISchema<T, AnyObject, any, any>'. Type 'ISchema<MakeKeysOptional<T>, AnyObject, any, any>' is not assignable to type 'Reference<unknown> | ISchema<T, AnyObject, any, any>'. Type 'ISchema<MakeKeysOptional<T>, AnyObject, any, any>' is not assignable to type 'ISchema<T, AnyObject, any, any>'. Type 'MakeKeysOptional<T>' is not assignable to type 'T'. 'MakeKeysOptional<T>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'object'. Type 'T | _<MakePartial<T>>' is not assignable to type 'T'. 'T | _<MakePartial<T>>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'object'. Type '_<MakePartial<T>>' is not assignable to type 'T'. '_<MakePartial<T>>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'object'. Type 'MakePartial<T> | { [k in keyof MakePartial<T>]: MakePartial<T>[k]; }' is not assignable to type 'T'. 'MakePartial<T> | { [k in keyof MakePartial<T>]: MakePartial<T>[k]; }' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'object'. Type 'MakePartial<T>' is not assignable to type 'T'. 'MakePartial<T>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'object'. Type '{}' is not assignable to type 'T'. '{}' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'object'.
The text was updated successfully, but these errors were encountered:
Assume I have the following defined:
and a generic Interface
IIngredient
:How can I implement a dynamic yup schema that validates an
IIngredient<T>
with a dynamicT
?I've tried it like this:
TypeError:
The text was updated successfully, but these errors were encountered: