fenok / react-router-typesafe-routes

Comprehensive and extensible type-safe routes for React Router v6 with first-class support for nested routes and param validation.
MIT License
151 stars 3 forks source link

Cannot declare nested routes #19

Closed jaysson closed 1 year ago

jaysson commented 1 year ago
const routes = {
    root: route('', {}, { auth: route('auth', {}) }),
};

Throws

Argument of type '{ auth: RouteWithChildren<void, "auth", Record<never, never>, Record<never, never>, never[], Record<never, never>>; }' is not assignable to parameter of type 'undefined'.

I am using typescript 4.9.4.

fenok commented 1 year ago

Hello! This is actually intentional. You're hitting a safeguard that prevents child routes from starting with a lowercase character. Granted, it's a bit confusing, but I'm not sure how to make the error message more user-friendly.

Quoting from the README (grammatical error fixed):

Child routes have to be in CONSTANT_CASE or PascalCase to prevent overlapping with other route fields.

As stated, the reason for this is to prevent clashing between child routes and (current and future) route API (such as path, buildUrl, types, etc.).

I also run tests for typescript v4.9.3, which seems to be the latest at the moment, and can confirm that everything works fine.

fenok commented 1 year ago

I'm closing this because it seems to work as intended. I mentioned this quirk in the "Limitations" section in README.

Please reopen if I'm missing something.

fenok commented 1 year ago

Addressed in https://github.com/fenok/react-router-typesafe-routes/pull/31