Skip to content

Layouts for paths that start with underscore (%5F) produces error for dev types of LayoutRoutes #93700

Description

@mdrayer

Link to the code that reproduces this issue

https://github.com/mdrayer/nextjs-layoutroutes-dev-types-issue

To Reproduce

  1. Start the app in dev mode: npm run dev
  2. Stop server and run the test script: npm t

Current vs. Expected behavior

Current behavior is that type errors happen:

.next/dev/types/validator.ts:24:44 - error TS2344: Type 'Route' does not satisfy the constraint 'LayoutRoutes'.
  Type 'import("/path/to/my-app-16.2.6/.next/dev/types/routes").LayoutRoutes' is not assignable to type 'import("/path/to/my-app-16.2.6/.next/types/routes").LayoutRoutes'.
    Type '"/%5Ffoo"' is not assignable to type 'LayoutRoutes'.

24   default: React.ComponentType<LayoutProps<Route>> | ((props: LayoutProps<Route>) => React.ReactNode | Promise<React.ReactNode> | never | void | Promise<void>)
                                              ~~~~~

.next/dev/types/validator.ts:24:75 - error TS2344: Type 'Route' does not satisfy the constraint 'LayoutRoutes'.
  Type 'import("/path/to/my-app-16.2.6/.next/dev/types/routes").LayoutRoutes' is not assignable to type 'import("/path/to/my-app-16.2.6/.next/types/routes").LayoutRoutes'.
    Type '"/%5Ffoo"' is not assignable to type 'LayoutRoutes'.

24   default: React.ComponentType<LayoutProps<Route>> | ((props: LayoutProps<Route>) => React.ReactNode | Promise<React.ReactNode> | never | void | Promise<void>)
                                                                             ~~~~~

.next/dev/types/validator.ts:67:31 - error TS2344: Type 'typeof import("/path/to/my-app-16.2.6/app/%5Ffoo/layout")' does not satisfy the constraint 'LayoutConfig<"/%5Ffoo">'.
  Types of property 'default' are incompatible.
    Type '({ children }: LayoutProps<"/_foo">) => Element' is not assignable to type 'ComponentType<LayoutProps<"/%5Ffoo">> | ((props: LayoutProps<"/%5Ffoo">) => void | ReactNode | Promise<ReactNode> | Promise<...>)'.
      Type '({ children }: LayoutProps<"/_foo">) => Element' is not assignable to type 'FunctionComponent<LayoutProps<"/%5Ffoo">>'.
        Types of parameters '__0' and 'props' are incompatible.
          Type 'LayoutProps<"/%5Ffoo">' is not assignable to type 'LayoutProps<"/_foo">'.
            Type 'LayoutProps<"/%5Ffoo">' is not assignable to type '{ params: Promise<{}>; children: ReactNode; }'.
              Types of property 'params' are incompatible.
                Type 'Promise<unknown>' is not assignable to type 'Promise<{}>'.
                  Type 'unknown' is not assignable to type '{}'.

67   type __Check = __IsExpected<typeof handler>
                                 ~~~~~~~~~~~~~~


Found 3 errors in the same file, starting at: .next/dev/types/validator.ts:24

Expected behavior is that no type errors with crop up.

Note that the type errors do not crop up if you clear you .next directory then rerun the test script. The issue seems to be that the dev type for LayoutRoutes uses the encoded underscore (type LayoutRoutes = "/" | "/%5Ffoo"), while the prod type for LayoutRoutes does not (type LayoutRoutes = "/" | "/_foo"). Expectation here is that either there would not be a difference between these or the dev types would not produce errors on tsc runs.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Wed Nov  5 21:32:34 PST 2025; root:xnu-11417.140.69.705.2~1/RELEASE_ARM64_T6020
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 24.11.1
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.28.0
Relevant Packages:
  next: 16.2.6 // Latest available version is detected (16.2.6).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

TypeScript, Route Handlers

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

Issue seems to be related to any version 16 of next. I do not see the issue on next v15 (15.5.18).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Route HandlersRelated to Route Handlers.TypeScriptRelated to types with Next.js.

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions