Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using route('/') instead of index('/') breaks typegen and type checking #13282

Closed
sam-cook opened this issue Mar 21, 2025 · 1 comment
Closed
Labels

Comments

@sam-cook
Copy link

I'm using React Router as a...

framework

Reproduction

https://stackblitz.com/edit/github-ckdgdgys

  1. Configure routes.ts file, with route('/', 'path/to/index.tsx') instead of index('path/to/index.tsx') route
  2. Run npm run typecheck
  3. .react-router/types/+register.ts has duplicate "/": {}; entry
  4. Type checking fails due to the duplicate entry
  5. At runtime application continues to work

System Info

System:
    OS: macOS 15.1.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 85.75 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.4.0 - /opt/homebrew/bin/node
    npm: 10.9.2 - /opt/homebrew/bin/npm
    pnpm: 8.9.2 - /opt/homebrew/bin/pnpm
    Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 134.0.6998.118
    Safari: 18.1.1
  npmPackages:
    @react-router/dev: ^7.3.0 => 7.3.0 
    @react-router/node: ^7.0.0 => 7.3.0 
    @react-router/serve: ^7.3.0 => 7.3.0 
    react-router: ^7.0.0 => 7.3.0 
    vite: ^5.4.14 => 5.4.14

Used Package Manager

npm

Expected Behavior

I see two routes of expected behaviour:

  • The react-router typegen command recognises you are using the route setup for everything instead of index() and does not create duplicate entries in the +register.ts types file.

OR

  • Documentation on the react-router website warns consumers of the requirement to at least have a base index() route
  • The react-router typegen command throws a descriptive error to point the user in the right direction

Option 2 may be easier to code for, since we can just check if there are NO routes with an index: true property.

Actual Behavior

  • react-router typegen command creates two "/": {}; entries in the .react-router/types/+register.ts file
  • Subsequent type checks fail with:
.react-router/types/+register.ts:10:3 - error TS2300: Duplicate identifier '/'.

10   "/": {};
     ~~~

.react-router/types/+register.ts:14:3 - error TS2300: Duplicate identifier '/'.

14   "/": {};
     ~~~


Found 2 errors in the same file, starting at: .react-router/types/+register.ts:10
@sam-cook sam-cook added the bug label Mar 21, 2025
@agussetyar
Copy link

This is related to #13182
Still waiting for the release patch

@timdorr timdorr closed this as completed Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants