tanstack-start: generated JSON fields typed as unknown (`_transforms`, session `metadata`) break createServerFn's serialisable return check in 4.0.0-beta.10

Aperta
#19,783 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@r1tsuu ci sta già lavorando.

Dal 20/11/2026.

  • #19784 di @AdityaxDeore — aperta

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

area: core Bug framework: tanstack-start Payload OSS
Describe the Bug

On 4.0.0-beta.10 with @payloadcms/tanstack-start, returning a Payload document from a TanStack Start server function no longer type-checks in TanStack's default strict mode.

Two fields new in the generated types are typed as JSON unknown, which TanStack's serialisability check rejects (TanStack maintainers consider this intended: https://github.com/TanStack/router/issues/5229):

  • _transforms on every upload collection (UploadTransforms.encoding: { [k: string]: unknown })
  • sessions[].metadata on auth collections ({ [k: string]: unknown } | unknown[] | ...), which reaches every document through the createdBy / updatedBy relationships to the user

So any server function returning a document with an upload field, or any document with createdBy/updatedBy, fails to compile. It compiled on 4.0.0-beta.6.

Link to the code that reproduces this issue

Minimal repro inside any @payloadcms/tanstack-start project with an upload collection media and an auth collection users:

import { createServerFn } from '@tanstack/react-start'
import { getPayload } from 'payload'
import config from '@payload-config'

export const getMedia = createServerFn({ method: 'GET' }).handler(async () => {
  const payload = await getPayload({ config })
  return payload.findByID({ collection: 'media', id: 1 })
})
Reproduction Steps
  1. Create a TanStack Start project on 4.0.0-beta.10 with an upload collection.
  2. Run payload generate:types.
  3. Add the server function above and run tsc --noEmit.

Error (abridged):

Argument of type '() => Promise<Media>' is not assignable to parameter of type 'ServerFn<Register, "GET", undefined, undefined, Promise<Media>, true>'.
  ...
    Types of property '_transforms' are incompatible.
      ...
        Types of property 'encoding' are incompatible.
          Type 'unknown' is not assignable to type 'SerializationError<"Type may not be serializable">'.

The same happens through createdBy → User → sessions → metadata.

Current workarounds are createServerFn({ strict: { output: false } }), which TanStack's docs discourage, or mapping documents to narrower types by hand. select doesn't help, because it doesn't narrow the generated return type here, and populate doesn't narrow nested relationships.

Could these JSON fields be generated with a serialisable JSON type (for example a recursive JsonValue) instead of unknown, at least when the TanStack adapter is used?

Which area(s) are affected?

area: core, framework: tanstack-start

Environment Info
payload: 4.0.0-beta.10
@payloadcms/tanstack-start: 4.0.0-beta.10
@payloadcms/db-postgres: 4.0.0-beta.10
@tanstack/react-start: 1.169.x
typescript: 6.0.3
node: 24
Lingua principale
TypeScript
Stelle
45.8k
Fork
4.4k
Merge medio
3g 4h
PR unite (30g)
210

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di payloadcms/payload

Tutte le issue di payloadcms/payload

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.