From 4cae1ae40f7098eaabe70ab3c276b613c4db4f06 Mon Sep 17 00:00:00 2001 From: devel-maverick Date: Wed, 3 Dec 2025 22:01:38 +0530 Subject: [PATCH] fix(router-core): correct TypeScript param inference for routes nested inside _pathless directories (#6011) --- packages/router-core/src/typePrimitives.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/router-core/src/typePrimitives.ts b/packages/router-core/src/typePrimitives.ts index 5f7d4b8e2f0..d779c22b27e 100644 --- a/packages/router-core/src/typePrimitives.ts +++ b/packages/router-core/src/typePrimitives.ts @@ -11,6 +11,11 @@ import type { AnyRouter, RegisteredRouter } from './router' import type { UseParamsResult } from './useParams' import type { UseSearchResult } from './useSearch' import type { Constrain, ConstrainLiteral } from './utils' +// Remove any `_pathless` folder segments for type extraction +export type StripPathless = + T extends `${infer A}/_pathless/${infer B}` + ? `${A}/${B}` + : T; export type ValidateFromPath< TRouter extends AnyRouter = RegisteredRouter, @@ -29,11 +34,16 @@ export type ValidateSearch< TFrom extends string = string, > = SearchParamOptions + export type ValidateParams< TRouter extends AnyRouter = RegisteredRouter, TTo extends string | undefined = undefined, TFrom extends string = string, -> = PathParamOptions +> = PathParamOptions< + TRouter, + StripPathless, + TTo extends string ? StripPathless : TTo +> /** * @private