Skip to content

TanStack Start server-entry requestContext type ignores @tanstack/react-start Register augmentation #7353

@alexander-zuev

Description

@alexander-zuev

Which project does this relate to?

TanStack Start / React Start server entry types.

Describe the bug

The current Server Entry Point docs say request context should be typed by augmenting @tanstack/react-start:

declare module '@tanstack/react-start' {
  interface Register {
    server: {
      requestContext: MyRequestContext
    }
  }
}

With that in place, this should typecheck:

import handler, { createServerEntry } from '@tanstack/react-start/server-entry'

export default createServerEntry({
  fetch(request, env, ctx) {
    return handler.fetch(request, {
      context: { deps: createAppDeps(env, ctx) },
    })
  },
})

In our app, TypeScript reports:

Object literal may only specify known properties, and deps does not exist in type BaseContext.

The reason appears to be that @tanstack/react-start/server-entry types ServerEntry using Register from @tanstack/react-router:

import type { Register } from '@tanstack/react-router'
export type ServerEntry = { fetch: RequestHandler<Register> }

So the documented @tanstack/react-start augmentation is not visible to serverEntry.fetch(...); the context type falls back to BaseContext.

Current workaround

We have to duplicate the same server.requestContext augmentation for both modules:

declare module '@tanstack/react-start' {
  interface Register {
    server: { requestContext: MyRequestContext }
  }
}

declare module '@tanstack/react-router' {
  interface Register {
    server: { requestContext: MyRequestContext }
  }
}

This typechecks, but it seems inconsistent with the public docs and leaks Start-specific server context into the router module augmentation.

Expected behavior

The documented @tanstack/react-start augmentation should be sufficient for handler.fetch(request, { context }) / createServerEntry(...).

Alternatively, the docs should mention that @tanstack/react-router also needs to be augmented for the server-entry fetch type.

Versions

@tanstack/react-start: 1.167.59
@tanstack/start-server-core: 1.167.26
@tanstack/start-client-core: 1.168.1
@tanstack/react-router: 1.169.1
TypeScript: 5.9.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions