Skip to content

[Typescript] onChange typing issue on e.target.value #1310

@chris-tse

Description

@chris-tse

Describe the bug

When using TypeScript 5.8.2, there is an issue with typing the e.target.value in the onChange handler. It throws a type error of TS2339: Property value does not exist on type EventTarget & HTMLInputElement as seen in screenshot.

Reverting back to 5.6.3 removes this error.

Your minimal, reproducible example

https://stackblitz.com/github/tanstack/form/tree/main/examples/react/simple?embed=1&theme=light&preset=node&file=src/index.tsx

Steps to reproduce

  1. Clone any of the examples into an environment where the TypeScript version can be selected (StackBlitz doesn't seem to allow changing versions)
  2. Set IDE TypeScript version to 5.8.2
  3. Type error shows up on e.target.value portion

Here is a simple snippet:

<form.Field
	name="name"
	validators={{
		onChange: ({ value }) => (!value ? 'A name is required' : undefined),
	}}
>
	{(field) => (
		<>
			<label htmlFor={field.name}>Label Text</label>
			<input
				value={field.state.value}
				name={field.name}
				onBlur={field.handleBlur}
				placeholder="placeholder"
				className={error ? 'border-red-500' : ''}
				onChange={(e) => field.handleChange(e.target.value)}
			/>
			<p>{field.state.meta.errors.length ? field.state.meta.errors.join(',') : '\u00A0'}</p>
		</>
	)}
</form.Field>

Expected behavior

No type error is present as value should be a valid property on HTMLInputElement

How often does this bug happen?

Every time

Screenshots or Videos

Image

Platform

  • OS: Mac
  • Browser: Chrome (Arc)
  • Version: 134

TanStack Form adapter

react-form

TanStack Form version

v1.1.0

TypeScript version

v5.8.2

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions