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

[Bug]: faliure to declare custom routes #9623

Closed
guaijie opened this issue Nov 22, 2022 · 1 comment
Closed

[Bug]: faliure to declare custom routes #9623

guaijie opened this issue Nov 22, 2022 · 1 comment
Labels

Comments

@guaijie
Copy link

guaijie commented Nov 22, 2022

What version of React Router are you using?

6.4.3

Steps to Reproduce

type RouteHandle = { foo?: string }

interface FooRoute extends Omit<RouteObject, 'children'> {
  handle?: RouteHandle 
  children?: FooRoute[]
};

const myRoutes: FooRoute[] = [
  {
    path: '/home',
    element: <h1>Home</h1>,
    handle: { foo: 'bar' }
  },
  {
    path: '/anotherPage',
    element: <h1>Another page</h1>,
    handle: { foo: 'somethingElse' }
  },
]

//  1. The type of the attribute "index" is incompatible. Cannot assign type "true" to type "false"
const router = createBrowserRouter(routes)

// 2. I defined RouteHandle this way, but there is no type inference when using useMatches
export declare function useMatches(): {
    id: string;
    pathname: string;
    params: Params<string>;
    data: unknown;
    handle: unknown;  //  why unknown ?
}[];

const matches= useMatches()
const handle = useMatches().at(-1)?.handle as Handle  // we need to cast it to get at them

1669130932(1)

Expected Behavior

Hopefully, I can define route type in this way

Actual Behavior

I cannot define route type in this way

@guaijie guaijie added the bug label Nov 22, 2022
@timdorr
Copy link
Member

timdorr commented Nov 23, 2022

#9427 (comment)

@timdorr timdorr closed this as completed Nov 23, 2022
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

2 participants