Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Vue : Type 'Ref<unknown>' is not assignable to type 'string'.ts(2322)

I am using Vue3 , type script , composition and vee-validate4 and Pinia store all together

this is user register from.

views/register

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const schema = yup.object({
  email: yup.string().required().email("لطفا ! ایمیل معتبر وارد کنید ."),
  password: yup.string().required().min(8, "کلمه عبور باید حداقل هشت کاراکتر باشد ."),
});

const { errors, handleSubmit } = useForm({
  validationSchema: schema,
});

const { value: email } = useField('email');
const { value: password } = useField('password');

and i have a method here for register

views/register

async function add() {
  try {
    const res = await useAuthStore().register({email,password})
      } catch (err: any) {}
}

But , here I have a typescript error .

enter image description here

and my Pinia store is like this

actions: {
    register( user:ICreateUser) {
      return AuthService.create(user).then(
        response => {
          this.status.loggedIn = false;
          return Promise.resolve(response.data);
        },
        error => {
          this.status.loggedIn = false;
          return Promise.reject(error);
        }
      );
    }
},

How cam I fix Typescript errors ?

>Solution :

Just add type to useField ⇒ take a look at https://github.com/logaretm/vee-validate/blob/main/packages/vee-validate/src/useField.ts#L68

Try something like.

const { value: email } = useField<string>('email')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading