-
Notifications
You must be signed in to change notification settings - Fork 29.3k
Open
Labels
TypeScriptRelated to types with Next.js.Related to types with Next.js.linear: nextConfirmed issue that is tracked by the Next.js team.Confirmed issue that is tracked by the Next.js team.
Description
Link to the code that reproduces this issue
https://codesandbox.io/p/sandbox/github/vercel/next.js/tree/canary/examples/reproduction-template
To Reproduce
-
Enable typed routes in
next.config.js
:// next.config.js module.exports = { experimental: { typedRoutes: true, }, }
-
Use
usePathname()
in a Client Component:'use client' import { usePathname } from 'next/navigation' import type { Route } from 'next' export default function Example() { const pathname = usePathname() const go = (p: Route) => {/* ... */} // Type error (pathname is string): // Argument of type 'string' is not assignable to parameter of type 'Route'. go(pathname) return null }

Current vs. Expected behavior
Expected Behavior
- With typed routes enabled,
usePathname()
should returnRoute
(or a branded equivalent), or - Provide a new hook (e.g.,
useTypedPathname()
/useCurrentRoute()
) or a helper/guard (e.g.,asRoute(pathname)
) to safely narrow the type at compile time.
Actual Behavior
usePathname()
returnsstring
, forcing unsafe casts and losing the refactor safety that Typed Routes aims to provide.
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000
Available memory (MB): 32768
Available CPU cores: 10
Binaries:
Node: 24.6.0
npm: 11.5.1
Yarn: 4.9.1
pnpm: 8.6.2
Relevant Packages:
next: 15.5.2
eslint-config-next: 15.5.2
react: 19.1.1
react-dom: 19.1.1
typescript: 5.4.5
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
TypeScript
Which stage(s) are affected? (Select all that apply)
Other (Deployed)
Additional context
When typedRoutes: true
is enabled, Link
and router.push/replace
become type-safe (Route
). However, usePathname()
still returns string
. Shouldn’t it return Route
(or provide a typed alternative) to keep parity with Typed Routes?
SuperJakov, sm17p, kawokas, HasanMothaffar, Dragate and 4 more
Metadata
Metadata
Assignees
Labels
TypeScriptRelated to types with Next.js.Related to types with Next.js.linear: nextConfirmed issue that is tracked by the Next.js team.Confirmed issue that is tracked by the Next.js team.