TanStack / TanStack/form

Field errors returned from onSubmitAsync aren't TS-checked

Open
#1,537 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question v1 v2: needs investigation
Dominant language
TypeScript
Stars
6.7k
Forks
682
Avg merge
5d 18h
Merged PRs (30d)
7

Description

Describe the bug

Form's onSubmitAsync validator allows returning object like this:

return {
    fields: {
        field1: `Field1 has a problem`
    }
}

Considering the strong type checks, I expected that if field1 didn't exist, Typscript would scream about this.

Your minimal, reproducible example

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgVwM4FMBi0RwL5wBmUEuA5AAIwCGAdqjQMYDWA9FOtYzALSE5kA3AChhjCPXj8ouALwoM2GQAoEwuBrgATdIWrIANjABq1A8nSoAXInWb71GwCInAGjv2NAIxsAGd-Z4AZoAbmbAWtQw0Na2npoSAMrIXiDAMACCqACetIw21Dl5cKpwYebo+ACUcLIAfHHxnhwwyFC0jU1NhMDoBlqxal3DmgAeNjBQFsEjgTPDeCJdQR747nhVIsLSIAB0AOboMJi9-QCStPzKZNRkm9s4B0cnfVoXV2Sjd1tAA

Steps to reproduce

The linked playground already contains the imho incorrect behavior.

Expected behavior

I expected Typescript error about the fields object containing unknown key.

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

This is about Typescript, not code running in browser.

TanStack Form adapter

react-form

TanStack Form version

1.12.0

TypeScript version

5.8.3

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript playground and the react-form adapter's onSubmitAsync typing. Reproduce the accepted unknown field key, then trace the relevant type definitions; done means TypeScript reports an error for fields that are not part of the form.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.