vercel / vercel/next.js

typedRoutes don't recognize parameter on rewritten url if preceded by path character

Open
#66,876 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug TypeScript
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/elastic-lucy-jfpczm?file=%2F.next%2Ftypes%2Flink.d.ts

To Reproduce

The error is in the generated types file.

Current vs. Expected behavior

If rewriting /@:username to /user/:username, I'd expect a generated type like /@${SafeSlug<T>} but instead I get /@[username].

Provide environment information
Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 21.6.0: Mon Feb 19 20:24:34 PST 2024; root:xnu-8020.240.18.707.4~1/RELEASE_X86_64
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.2.0
  npm: 10.7.0
  Yarn: N/A
  pnpm: 7.33.7
Relevant Packages:
  next: 14.2.0 // There is a newer version (14.2.4) available, upgrade recommended! 
  eslint-config-next: 14.2.0
  react: 18.3.1
  react-dom: 18.3.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)

next dev (local)

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the linked CodeSandbox reproduction and inspect the generated .next/types/link.d.ts file. Compare the generated route type for a rewrite from /@:username to /user/:username with the expected parameterized form. Done means the generated type preserves the username parameter when it follows a path character.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.