[v2] FieldWithValue<T> erases field.name to any instead of string
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 79/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- react, typescript
- Ambito
- backend-api-design
Direzione di ricerca
Leggi l’alias FieldWithValue in packages/form-core/src/types.public.ts e verifica come il suo primo argomento di tipo FieldApi determina field.name. Usa la riproduzione TypeScript autonoma nell’issue per confermare il comportamento attuale e l’argomento candidato string. Il lavoro è completato quando il nome rifiuta le operazioni numeriche, mentre la tipizzazione del valore booleano e degli aggiornamenti continua a funzionare; l’issue non indica alcun file di test upstream.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 6.8k
- Fork
- 705
- Merge medio
- 1g 7h
- PR unite (30g)
- 13
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/form
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`Forse già presa @fenet-as l’ha presa 23 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
TanStack/form#2427 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Async validator doesn't re-trigger `isValidating` after first failed validationForse già presa @drewsephski l’ha presa 27 giorni fa. Aperta
Difficoltà 2/5 1-2 giorni Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
[v2 alpha] devtools are always light modeForse già presa @dikshit-n l’ha presa 61 giorni fa. Apertaarea: runtime scope: devtools type: bug v2
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
FormGroupApi.getRelatedFields and FieldApi.validate() use unguarded startsWith for group membership, matching unrelated fields with a shared name prefixForse già presa @HDPark95 l’ha presa 80 giorni fa. Apertaarea: runtime scope: core type: bug v1
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
TanStack/form#2337 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
FormApi: onSubmit/onServer error cleared on any non-matching validation cause, not just 'change'Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertav1 v2: needs investigation
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TanStack/form
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
I maintainer di solito rispondono entro 1 giorno
-
Invalid-link error for static location apps shows HTML-escaped sample URL (`/`)Forse già presa @cgmuniz l’ha presa oggi. Aperta🐛 bug
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 2 giorni
-
apps/stage-web bug env/os-linux pending triage scope/audio-output
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
opencrvs/opencrvs-core#14341 ·
I maintainer di solito rispondono entro 1 giorno