typescripttanstack-router

tanstack/react-router: Argument of type 'string' is not assignable to parameter of type 'never'



I am TypeScript beginner and learning `tanstack/react-router`. However, I couldn't figure out why vscode keeps showing error message `Argument of type 'string' is not assignable to parameter of type 'never'` from `createLazyFileRoute` function
// index.lazy.tsx
import { createLazyFileRoute } from "@tanstack/react-router";

function Index() { }

export const Route = createLazyFileRoute("/")({
    component: Index
});

This code snippet was copied from Tanstack Router - Quick Start


Solution

  • Tanstack Router generates a file routeTree.gen.ts which declares the interface FileRoutesByPath that createLazyFileRoute uses to map the possible paths. You can either run tsr watch or tsr generate or, if using a bundler plugin, build your project or start a dev server.

    Here is a guide on setting up the file based router for different environments.