router-core-type-safety

Enforces full type inference patterns for TanStack Router hooks, links, and route trees.

Updated Dec 21, 2025
One-click install
npx skills add https://github.com/Angael/veles --skill router-core-type-safety-angael
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: router-core-type-safety
Source: https://github.com/Angael/veles/tree/main/.agents/skills/router-core-type-safety
Command: npx skills add https://github.com/Angael/veles --skill router-core-type-safety-angael

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/react-router.

What problem does it solve? TanStack Router infers types for params, search, context, and loader data automatically, but developers frequently break this inference by adding casts, annotations, or generic parameters, or by forgetting the Register module declaration, resulting in untyped navigation and slow TypeScript checks. ## Core Features & Use Cases - Inference-First Patterns: Teaches the single required Register module declaration and how to let Route.useParams, Route.useSearch, and Route.useLoaderData flow without any annotations or casts. - Narrowing and Performance: Covers from narrowing on hooks and Link, strict:false for shared components, getRouteApi for code-split files, object-syntax addChildren, and as const satisfies for LinkProps to keep TypeScript checks fast. - Use Case: When building a dashboard route with search params and loader data, apply this Skill to wire up typed hooks, typed Link navigation, and ValidateLinkOptions-based reusable nav components without a single cast. ## Quick Start Ask the AI to review your TanStack Router routes and remove all type casts while adding the Register declaration and from narrowing to every Link and hook.

Frequently Asked Questions about router-core-type-safety

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I get type-safe routing in TanStack Router?

Register your router type once with declare module '@tanstack/react-router' and an interface Register containing router: typeof router. After that, every Link, useNavigate, useSearch, and useParams across the app is fully typed with no further annotations.

How to type useSearch and useParams in TanStack Router?

Do not annotate them at all; types are inferred from the route definition. Narrow the hook with the from option, such as useSearch({ from: '/posts/$postId' }), so it returns that route's exact search params instead of a union of all routes.

Why is TanStack Router TypeScript checking so slow?

Slow checks usually come from un-narrowed LinkProps unions, missing from narrowing on Link and hooks, or loaders returning large inferred types into the route tree. Use as const satisfies LinkProps, add from, and prefer void-returning loaders with TanStack Query.

Can I use react-router-dom hooks with TanStack Router?

No. Imports like useSearchParams from react-router-dom or useRouter from next/navigation are different libraries and will break the build or create conflicting routes. All routing exports must come from @tanstack/react-router.

When should I use strict:false instead of from in TanStack Router?

Use strict:false for shared components rendered across multiple routes, such as a global search bar, where the hook should return a union of all routes' params without runtime errors. Use from when the component belongs to one specific route.