fabian-hiller / modular-forms

The modular and type-safe form library for SolidJS, Qwik and Preact
https://modularforms.dev
MIT License
956 stars 47 forks source link

Typescript error after updating to Qwik 1.3.0 #158

Open Przemoo16 opened 7 months ago

Przemoo16 commented 7 months ago

After updating Qwik to 1.3.0, the required validator throws the typescript error: Type 'QRL<(value: Value<undefined>) => string>' is not assignable to type 'QRL<ValidateField<string>>'.ts(2322)

Code to reproduce:

import { component$ } from '@builder.io/qwik';
import { required, useForm } from '@modular-forms/qwik';

export type FormSchema = {
  test: string;
};

export const Component = component$(() => {
  const [form, { Form, Field }] = useForm<FormSchema>({
    loader: {
      value: { test: '' },
    },
  });

  return (
    <Form>
      <Field name="test" validate={[required('This field is required')]}>
        {(field, props) => <input {...props} type="text" value={field.value} />}
      </Field>
    </Form>
  );
});
fabian-hiller commented 7 months ago

Thank you for reporting this issue. I will look into it in the next few days. If there is a problem with Qwik v1.3.0, I recommend downgrading as a workaround.

fabian-hiller commented 7 months ago

Alternatively, you can also use a Valibot schema for validation: https://modularforms.dev/qwik/guides/validate-your-fields#schema-validation

fabian-hiller commented 7 months ago

I am not sure why TypeScript stopped resolving types the correct way. As a workaround, you can define the correct type yourself:

required<string>('This field is required')
Przemoo16 commented 7 months ago

The custom$ also required explicit type, as typescript somehow cannot inference it.

fabian-hiller commented 7 months ago

Yes, there was probably a change somewhere in the Qwik code that now breaks some type inferences. I will be investigating this in the next few weeks.