Skip to content

Conversation

@brhx
Copy link
Member

@brhx brhx commented Nov 1, 2025

Summary by CodeRabbit

  • Tests

    • Expanded type-level test coverage for serializable input validation and server function return types, including union handling and distribution scenarios.
  • Refactor

    • Improved type handling for Promise-like responses in server functions with recursive unwrapping to provide more consistent and predictable type inference.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 1, 2025

Walkthrough

The ServerFnReturnType type in the start-client-core module was updated to add recursive unwrapping of PromiseLike types. When a TResponse is PromiseLike, it now resolves to Promise<ServerFnReturnType<TRegister, U>>, enabling uniform handling of nested promises. Corresponding type-level tests were expanded to validate serializable input constraints and union distribution.

Changes

Cohort / File(s) Change Summary
Type Definition Update
packages/start-client-core/src/createServerFn.ts
Updated ServerFnReturnType signature to add a new conditional branch that checks if TResponse extends PromiseLike<infer U> and recursively unwraps it to Promise<ServerFnReturnType<TRegister, U>>. Existing Response and non-promise type handling preserved.
Type-Level Tests
packages/start-client-core/src/tests/createServerFn.test-d.ts
Added imports for ValidateSerializableInput, ConstrainValidator, and ServerFnReturnType. Extended tests to cover serializable input validation, union type distribution through ServerFnReturnType, and return type constraints using Awaited and ReturnType utilities.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Focus on verifying the conditional type logic correctly handles the PromiseLike branch without introducing regressions to existing Response and non-promise cases
  • Ensure the recursive unwrapping semantics align with intended usage patterns in the codebase
  • Validate test cases adequately cover union types and nested promise scenarios

Possibly related PRs

  • fix: raw response handling #5276: Concurrently modifies ServerFnReturnType in the same file; changed the conditional to use Awaited<TResponse> while this PR adds PromiseLike recursive unwrapping logic.

Suggested reviewers

  • chorobin

Poem

🐰 A promise wrapped in promise's veil,
Now unwrapped with recursive detail,
Types cascade through nested dreams,
Uniform flows in TypeScript streams! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "fix: Make serverFn union response type distributive" directly and accurately describes the primary change in the changeset. The main modification updates the ServerFnReturnType type signature to add a Promise-like unwrapping branch that makes union types distribute properly through the conditional type logic, which is exactly what the title conveys. The title is specific and technical, using appropriate terminology that developers would understand when scanning commit history, avoiding vague language or unnecessary noise. The "fix:" prefix correctly categorizes this as a bug fix related to type handling.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Nov 1, 2025

View your CI Pipeline Execution ↗ for commit 43b87ad

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 5m 56s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 27s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-01 13:08:37 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 1, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5720

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5720

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5720

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5720

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5720

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5720

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5720

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5720

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5720

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5720

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5720

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5720

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5720

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5720

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5720

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5720

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5720

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5720

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5720

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5720

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5720

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5720

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5720

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@5720

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5720

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5720

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5720

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5720

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5720

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5720

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5720

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5720

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5720

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5720

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5720

commit: 43b87ad

@brhx brhx marked this pull request as ready for review November 1, 2025 20:33
@schiller-manuel schiller-manuel changed the title Make serverFn union response type distributive fix:: Make serverFn union response type distributive Nov 1, 2025
@schiller-manuel schiller-manuel changed the title fix:: Make serverFn union response type distributive fix: Make serverFn union response type distributive Nov 1, 2025
@schiller-manuel schiller-manuel merged commit a9d23a4 into TanStack:main Nov 1, 2025
6 checks passed
@brhx brhx deleted the response-union branch November 2, 2025 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants