-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
Which project does this relate to?
Start
Describe the bug
When using createServerFn from @tanstack/start, a TypeScript error occurs if the handler's return type is an object that includes a property with the unknown type. The type inference seems to fail, causing a type mismatch error.
Your Example Website or App
https://tanstack.com/start/latest/docs/framework/react/server-functions#validation-with-zod
Steps to Reproduce the Bug or Issue
- Define a type with a property of type unknown.
- Create a server function using createServerFn.
- In the .handler(), return an object that conforms to the defined type.
example code:
import { createServerFn } from '@tanstack/start';
type Res = {
text: string;
metaData: unknown;
};
const loader = createServerFn().handler(async () => {
const res: Res = {
text: 'hello',
metaData: {
tag: 'first',
},
};
return res;
});error message
Argument of type '() => Promise<Res>' is not assignable to parameter of type 'ServerFn<Register, Method, undefined, undefined, Res>'.
Type 'Promise<Res>' is not assignable to type 'ServerFnReturnType<Register, Res>'.
Type 'Promise<Res>' is not assignable to type 'Promise<{ text: string; metaData: {}; }>'.
Type 'Res' is not assignable to type '{ text: string; metaData: {}; }'.
Types of property 'metaData' are incompatible.
Type 'unknown' is not assignable to type '{}'.ts(2345)Expected behavior
Correct use of type
Screenshots or Videos
No response
Platform
- Router / Start Version: 1.132.6
- OS: Windows
- Browser: [e.g. Chrome, Safari, Firefox]
- Browser Version: [e.g. 91.1]
- Bundler: vite
- Bundler Version: 7.1.7
Additional context
No response
majoncas-ue and nilsbunger
Metadata
Metadata
Assignees
Labels
No labels