[v2] FieldWithValue<T> erases field.name to any instead of string
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 79/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- react, typescript
- Domínio
- backend-api-design
Direção de pesquisa
Leia o alias FieldWithValue em packages/form-core/src/types.public.ts e verifique como seu primeiro argumento de tipo FieldApi determina field.name. Use a reprodução independente em TypeScript no issue para confirmar o comportamento atual e o argumento candidato string. O trabalho está concluído quando o nome rejeitar operações numéricas, enquanto a tipagem do valor booleano e das atualizações continuar funcionando; o issue não indica nenhum arquivo de teste upstream.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- TypeScript
- Estrelas
- 6.8k
- Forks
- 711
- Merge médio
- 1d 6h
- PRs com merge (30d)
- 12
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de TanStack/form
-
Submit listener exceptions leave isSubmitting stuck trueTalvez já em andamento @henricop assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
handleSubmit calls onSubmit again while a submit is still pending (since 1.33.1)Talvez já em andamento @twotnguyen assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`Talvez já em andamento @fenet-as assumiu há 26 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
TanStack/form#2427 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Async validator doesn't re-trigger `isValidating` after first failed validationTalvez já em andamento @drewsephski assumiu há 30 dias. Aberta
Dificuldade 2/5 1-2 dias Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
[v2 alpha] devtools are always light modeTalvez já em andamento @dikshit-n assumiu há 64 dias. Abertaarea: runtime scope: devtools type: bug v2
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
Mantenedores costumam responder em até 1 dia
Todas as issues de TanStack/form
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Mantenedores costumam responder em até 1 dia
-
documentation easy good first issue help wanted
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 83/100
Mantenedores costumam responder em até 1 dia
-
Billion-context documentation addendum: nudge is independent of window occupancy. | billion-context 文档补充:nudge 与窗口占用无关Talvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 86/100
ranxianglei/billion-context#5893 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 79/100
microsoft/monaco-editor#5575 ·
Mantenedores costumam responder em até 1 dia
-
enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100