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

Đang mở
#19,783 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@r1tsuu đang làm issue này rồi.

Từ ngày 20/11/2026.

  • #19784 của @AdityaxDeore — đang mở

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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
Ngôn ngữ chính
TypeScript
Star
45.8k
Fork
4.4k
Merge trung bình
3 ngày 4 giờ
Pull request đã merge (30 ngày)
210

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của payloadcms/payload

Tất cả issue của payloadcms/payload

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.