[v2] FieldWithValue<T> erases field.name to any instead of string
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 79/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- react, typescript
- Domaine
- backend-api-design
Piste de recherche
Lis l’alias FieldWithValue dans packages/form-core/src/types.public.ts et vérifie comment son premier argument de type FieldApi détermine field.name. Utilise la reproduction TypeScript autonome de l’issue pour confirmer le comportement actuel et l’argument candidat string. Le travail est terminé lorsque le nom refuse les opérations sur les nombres, tandis que le typage de la valeur booléenne et des mises à jour continue de fonctionner ; l’issue ne nomme aucun fichier de test upstream.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the bug
In 2.0.0-alpha.3, the recommended reusable-field prop type FieldWithValue<T> erases field.name to any, rather than widening the concrete field-path literal to string.
I understand that the helper intentionally erases the specific name, error, and owning form types. This report is not asking it to preserve a particular path such as "enabled"; it is about retaining the basic string guarantee while accepting any field path.
For example, a reusable checkbox/switch accepting FieldWithValue<boolean> gets correctly typed field.value and field.handleChange, but field.name.toFixed() and assigning field.name to a number are both accepted. This also exposes any to type-aware linting when forwarding the name to a native input.
Minimal reproducible example / steps
This reproduces in a standalone directory with the actual package name, without an npm alias, Next.js, a UI library, or the consuming application's configuration.
Install:
pnpm init
pnpm add @tanstack/[email protected] [email protected]
pnpm add -D [email protected] @types/[email protected]
Save as expected.ts:
import type { FieldWithValue } from '@tanstack/react-form'
declare const field: FieldWithValue<boolean>
// @ts-expect-error A field path is not a number.
const invalidNumber: number = field.name
// @ts-expect-error A field path does not have Number.prototype.toFixed.
field.name.toFixed()
// @ts-expect-error A boolean field cannot be updated to a string.
field.handleChange('not a boolean')
Run:
pnpm exec tsc --ignoreConfig --noEmit --strict --skipLibCheck --module NodeNext --target ES2022 expected.ts
Actual result:
expected.ts(5,1): error TS2578: Unused '@ts-expect-error' directive.
expected.ts(8,1): error TS2578: Unused '@ts-expect-error' directive.
The third directive is correctly consumed, confirming value typing is preserved. Removing the first two directives makes the entire file compile successfully, even though the numeric operations are invalid for a field-path string.
I also verified in a separate TSX reproduction that useForm({ defaultValues: { enabled: false } }) supplies the literal "enabled" to the <form.Field name="enabled"> render prop. Passing that field into a component accepting FieldWithValue<boolean> is where the name becomes any; wrapping the reusable component with getFormHookHelpers().fieldComponent.loose is not necessary to trigger the issue.
Expected behavior
FieldWithValue<T>['name'] should be string, while the value/update types remain T and the component can still accept fields at arbitrary paths. The first two directives above should be consumed rather than reported as unused.
Suspected cause / possible direction
The published alias is:
type FieldWithValue<TFieldValue> = FieldApi<any, TFieldValue, any, any, any>
FieldApi exposes get name(): TFieldName, so the first any directly becomes the property's type. The same definition is still present on the alpha branch at 2b4fc5c.
Could that first argument be string instead? I tested a local candidate alias FieldApi<string, TFieldValue, any, any, any> without modifying the installed library. It rejects both invalid name operations, preserves boolean update checking, accepts the concrete field from the render prop, and is accepted by both fieldComponent.strict and fieldComponent.loose in the minimal TSX reproduction. This is a candidate direction, not a claim that the full upstream suite has been checked.
Frequency
Every time.
Platform
Linux; compile-time TypeScript issue, no browser required.
TanStack Form adapter
react-form (the alias is defined in form-core).
TanStack Form version
@tanstack/react-form and its @tanstack/form-core dependency: 2.0.0-alpha.3 (current npm alpha tag when checked).
TypeScript version
7.0.2. Standalone reproduction uses React 19.3.1 and @types/react 19.3.0.
- Langage dominant
- TypeScript
- Étoiles
- 6.8k
- Forks
- 705
- Merge moyen
- 1 j 6 h
- PR mergées (30 j)
- 12
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de TanStack/form
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`Peut-être pris @fenet-as l’a pris il y a 25 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
TanStack/form#2427 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Async validator doesn't re-trigger `isValidating` after first failed validationPeut-être pris @drewsephski l’a pris il y a 30 jours. Ouverte
Difficulté 2/5 1-2 jours Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
[v2 alpha] devtools are always light modePeut-être pris @dikshit-n l’a pris il y a 64 jours. Ouvertearea: runtime scope: devtools type: bug v2
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
Les mainteneurs répondent en général sous 1 jour
-
FormGroupApi.getRelatedFields and FieldApi.validate() use unguarded startsWith for group membership, matching unrelated fields with a shared name prefixPeut-être pris @HDPark95 l’a pris il y a 82 jours. Ouvertearea: runtime scope: core type: bug v1
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
TanStack/form#2337 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de TanStack/form
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
binding:python bug
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 1 jour
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
coollabsio/orbit#72 ·
Les mainteneurs répondent en général sous 1 jour
-
Bug
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
Les mainteneurs répondent en général sous 1 jour
-
bug needs-triage potential-regression
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
aws/aws-sdk-js-v3#8408 ·
Les mainteneurs répondent en général sous 1 jour