Skip to content

fix accessing array field type by path #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

create-signal
Copy link

@create-signal create-signal commented May 27, 2025

The Field component seems to show type errors when used with an Array field that is not an object - for example:

const TestComponent = () => {
  const [form, { Form, Field }] = createForm<{ values: number[] }>({
    initialValues: { values: [1, 2, 3] },
  });

  return (
    <Form onSubmit={() => {}}>
      <Field name="values.0" type="number">
        {(field, props) => (
          <input type="number" {...props} value={field.value} />
        )}
      </Field>
    </Form>
  );
};

Will show the errors

  • on the "type" prop - "Type 'string' is not assignable to type 'undefined'."
  • the type of "field.value" will be "undefined"

This PR updates the PathValue helper to allow looking up a value by array index

@create-signal create-signal changed the title fix accessing array field value by path fix accessing array field type by path May 27, 2025
@fabian-hiller
Copy link
Owner

Hey! This library is currently kind of in maintenance mode as I plan to rewrite it at some point. Is this issue preventing you from using the library?

@fabian-hiller fabian-hiller self-assigned this May 29, 2025
@fabian-hiller fabian-hiller added the bug Something isn't working label May 29, 2025
@create-signal
Copy link
Author

Nope! The type errors can be suppressed with @ts-expect-error and the library works as expected. Perhaps I turn this PR into an Issue instead to make it more easily searchable for others experiencing the same issue?

@fabian-hiller
Copy link
Owner

You can leave it as it is. I think that's fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants