-
|
I want to create custom link but I just don't to accept any link, I want it to only accept paths that has {page: number} search query |
Beta Was this translation helpful? Give feedback.
Answered by
FatahChan
Feb 19, 2026
Replies: 1 comment
-
|
AI code after many attepts import type { FileRoutesByTo } from '@/routeTree.gen'
/** Checks that schema TSchema has all keys from TShape with compatible value types */
type SchemaMatchesShape<TSchema, TShape extends Record<string, unknown>> = {
[K in keyof TShape]: K extends keyof TSchema
? TSchema[K] extends TShape[K]
? 1
: 0
: 0
}[keyof TShape] extends 1
? true
: false
/**
* Extracts route paths whose fullSearchSchema matches the given shape.
* TanStack Router stores the resolved search schema in route.types.fullSearchSchema.
*
* @example
* ExtractPathsWithSearchSchema<FileRoutesByTo, { page: number }> // required page
* ExtractPathsWithSearchSchema<FileRoutesByTo, { page: number | undefined }> // optional page (z.number().optional())
* ExtractPathsWithSearchSchema<FileRoutesByTo, { page?: number; search?: string }>
*/
type ExtractPathsWithSearchSchema<T, TShape extends Record<string, unknown>> = {
[K in keyof T]: T[K] extends {
types: {
fullSearchSchema: infer TSchema
}
}
? SchemaMatchesShape<TSchema, TShape> extends true
? K
: never
: never
}[keyof T]
export type PageSearchRoutePath = ExtractPathsWithSearchSchema<
FileRoutesByTo,
{ page: number | undefined }
> |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
FatahChan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AI code after many attepts