anatolykopyl / vuelidate-nesting-question

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vuelidate Nesting Question

How do you make a validator for a data structure with a field that has nested fields?

App.vue has a form with a Vuelidate validator. It consists of a name, an address and an optional second Address. Problem is that useVuelidate throws a typescript error on it's second parameter userForm.

Argument of type 'Ref<{ name: string; address: { city: string; street: string; }; secondAddress?: { city: string; street: string; } | undefined; }>' is not assignable to parameter of type '{ name: any; address: any; secondAddress: any; } | Ref<{ name: any; address: any; secondAddress: any; }> | ToRefs<{ name: any; address: any; secondAddress: any; }>'.
  Type 'Ref<{ name: string; address: { city: string; street: string; }; secondAddress?: { city: string; street: string; } | undefined; }>' is not assignable to type 'Ref<{ name: any; address: any; secondAddress: any; }>'.

This happens because the interface UserForm has secondAddress marked as optional.

Question

How do you write the rules in this case, where the field with children is optional?

About


Languages

Language:CSS 45.5%Language:Vue 32.8%Language:HTML 12.5%Language:TypeScript 9.2%