`SessionManager` type not exported from public API, causing type inference issues
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.1k
- Forks
- 1.9k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 143
Description
Description
When using useSession and wrapping it in a function (common pattern for creating a typed session helper), TypeScript cannot infer the return type without a reference to internal module paths.
Expected Behavior
The SessionManager type should be exported from @tanstack/react-start/server (and equivalent for solid/vue) so users can properly type their session helper functions.
Actual Behavior
Only SessionConfig is exported from the public API. SessionManager is defined in session.ts but not re-exported through index.ts.
This causes the following TypeScript error:
The inferred type of 'getAppSession' cannot be named without a reference to
'../../../../../../node_modules/.pnpm/@tanstack+start-server-core@1.150.0/node_modules/@tanstack/start-server-core/dist/esm/session'.
This is likely not portable. A type annotation is necessary.
Reproduction
// utils/session.ts
import { useSession } from '@tanstack/react-start/server'
type SessionData = {
userId?: string
}
// ❌ This causes type error - cannot infer return type
export function useAppSession() {
return useSession<SessionData>({
password: process.env.SESSION_SECRET!,
})
}
Workaround
Currently users must derive the type manually:
import { useSession } from '@tanstack/react-start/server'
type SessionData = { userId?: string }
// Derive SessionManager type since it's not exported
type AppSessionManager = Awaited<ReturnType<typeof useSession<SessionData>>>
export function useAppSession(): Promise<AppSessionManager> {
return useSession<SessionData>({
password: process.env.SESSION_SECRET!,
})
}
Suggested Fix
Export SessionManager, Session, SessionData, and SessionUpdate types from @tanstack/start-server-core/src/index.tsx:
// packages/start-server-core/src/index.tsx
- export type { SessionConfig } from './session'
+ export type { SessionConfig, SessionManager, Session, SessionData, SessionUpdate } from './session'
These types are already defined and used internally in request-response.ts, they just need to be re-exported publicly.
Environment
@tanstack/react-start: 1.149.4 / 1.150.0@tanstack/start-server-core: 1.150.0- TypeScript: 5.x
- Node: 22.x
Additional Context
The official documentation shows the useAppSession() pattern but doesn't mention this typing issue:
The types exist in packages/start-server-core/src/session.ts:
SessionManager<T>(lines 42-47)Session<T>(lines 33-37)SessionData<T>(line 32)SessionUpdate<T>(lines 39-40)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with packages/start-server-core/src/session.ts to review the existing SessionManager, Session, SessionData, and SessionUpdate types, then inspect their exports in packages/start-server-core/src/index.tsx. Verify the public @tanstack/start-server-core exports and confirm the useAppSession reproduction no longer requires an internal module path or manual derived annotation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, developer-experience
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100