Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

Regression (7.0.0-dev.20260624.1): intersection type member dropped in generic position — TanStack Router stripSearchParams rejected (TS2322), clean in tsc + 20260623.1 #4462

Closed

Description

@meabed

Summary

Starting with @typescript/[email protected], tsgo reports a spurious TS2322 on valid TanStack Router code.

A route's resolved search schema is the intersection of its parent's search schema and the route's own validateSearch output. When that schema is used as a type argument (here, for the stripSearchParams search middleware), tsgo drops the route's own member from the intersection, leaving only the parent's. The middleware — correctly typed SearchMiddleware<Parent & Own> — is then checked against SearchMiddleware<Parent> and rejected.

The identical code compiles cleanly with stable tsc (6.0.3) and with tsgo 7.0.0-dev.20260623.1. It bisects to 20260624.1.

This is likely the same underlying regression as #4391 (also TanStack router-core, same build window) — there a const type parameter loses a string-literal property through Omit<...>, surfacing as TS2353. This report is a smaller, different surface (an intersection member dropped in a generic position, surfacing as TS2322).

Downstream report (same repro, library-user perspective): TanStack/router#7709.

Version matrix (same code, only the compiler changes)

Compiler Result
stable tsc 6.0.3 ✅ no errors
tsgo 7.0.0-dev.20260623.1 ✅ no errors
tsgo 7.0.0-dev.20260624.1 (first bad) ❌ TS2322
tsgo 7.0.0-dev.20260627.2 (latest) ❌ TS2322

Environment: macOS (darwin, arm64). @tanstack/[email protected], @tanstack/[email protected], [email protected].

Reproduction

src/
  routes/
    __root.tsx
    pricing.tsx
  routeTree.gen.ts   # generated by @tanstack/router-cli
tsconfig.json
tsr.config.json

src/routes/__root.tsx — root route validates a shared page search param:

import { createRootRoute, Outlet } from '@tanstack/react-router';
import { zodValidator } from '@tanstack/zod-adapter';
import { z } from 'zod';

export const Route = createRootRoute({
  validateSearch: zodValidator(z.object({ page: z.coerce.number().default(1) })),
  component: () => <Outlet />,
});

src/routes/pricing.tsx — leaf route adds its own billing param and uses stripSearchParams:

import { createFileRoute, stripSearchParams } from '@tanstack/react-router';
import { zodValidator } from '@tanstack/zod-adapter';
import { z } from 'zod';

const defaults = { billing: 'monthly' } as const;

export const Route = createFileRoute('/pricing')({
  validateSearch: zodValidator(z.object({ billing: z.enum(['monthly', 'yearly']).default('monthly') })),
  search: { middlewares: [stripSearchParams(defaults)] },
  component: Page,
});

function Page() {
  return Route.useSearch().billing;
}

Steps:

npm install
npx tsr generate          # @tanstack/router-cli -> writes src/routeTree.gen.ts
npx tsgo --noEmit         # tsgo
# compare:  npx tsc --noEmit   (stable, clean)

Expected

No error. The route's search schema is { page: number } & { billing: 'monthly' | 'yearly' }, and stripSearchParams({ billing: 'monthly' }) yields a SearchMiddleware for exactly that type. (Stable tsc and tsgo 20260623.1 both accept it.)

Actual (tsgo >= 20260624.1)

src/routes/pricing.tsx(10,27): error TS2322: Type 'SearchMiddleware<{ billing: "monthly" | "yearly"; } & { page: number; }>' is not assignable to type 'SearchMiddleware<{ page: number; }>'.

The expected type has collapsed to the parent-only { page: number } — the route's own { billing } member is dropped from the intersection in this generic position.

Real-world impact

In a full app (root validateSearch + many file routes), this same root cause cascades widely: TS2322 on every stripSearchParams middleware, plus TS2339 on Route.useSearch().<ownField> and TS2353 on navigate({ search }) object literals, because the per-route resolved search schema everywhere falls back to the root-only schema. A single mid-size app surfaced ~156 such errors on 20260627.2, all clean on 20260623.1.

Activity

  1. meabed commented on Jun 27, 2026

    @meabed
    Author

    Runnable reproduction repo: https://github.com/meabed/tsgo-tanstack-router-search-repro

    git clone https://github.com/meabed/tsgo-tanstack-router-search-repro
    cd tsgo-tanstack-router-search-repro
    npm install
    npx tsgo --noEmit   # TS2322 on @typescript/native-preview >= 7.0.0-dev.20260624.1
    npx tsc  --noEmit   # clean

    (src/routeTree.gen.ts is committed, so no generate step needed; re-run npx tsr generate if you change the routes.)

  2. jakebailey commented on Jun 28, 2026

    @jakebailey
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions