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