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

Type inference issue with meta function's matches argument #12956

Open
tobigumo opened this issue Feb 5, 2025 · 0 comments
Open

Type inference issue with meta function's matches argument #12956

tobigumo opened this issue Feb 5, 2025 · 0 comments
Labels

Comments

@tobigumo
Copy link

tobigumo commented Feb 5, 2025

I'm using React Router as a...

framework

Reproduction

https://stackblitz.com/edit/github-jh2463uj?file=app%2Froutes%2Fhome.tsx

function "meta" in home.tsx

export function meta({ matches }: Route.MetaArgs) {
  // In versions prior to v7.0.1, the parent route data was inferred correctly.
  // From v7.0.2 onwards, match.id becomes unknown and type inference fails.
  const metaMatch = matches.find((match) => match && match.id === 'root');
  return [
    { title: 'New React Router App' },
    { name: 'description', content: 'Welcome to React Router!' },
  ];
}

System Info

I tested it with React Router v7.0.1, v7.0.2, and v7.1.5.


  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @react-router/dev: 7.0.2 => 7.0.2 
    @react-router/node: 7.0.2 => 7.0.2 
    @react-router/serve: 7.0.2 => 7.0.2 
    react-router: 7.0.2 => 7.0.2 
    vite: ^5.4.11 => 5.4.14

Used Package Manager

npm

Expected Behavior

In versions prior to v7.0.1, the parent route data was inferred correctly.

match is inferred as follows:

(parameter) match: {
    id: "root";
    params: {};
    pathname: string;
    meta: MetaDescriptor[];
    data: {
        path: string;
    };
    handle?: unknown;
    error?: unknown;
}

Actual Behavior

From v7.0.2 onwards, match.id becomes unknown and type inference fails.

match is inferred as follows:

(parameter) matches: [{
    id: "root";
    params: {} & {
        [key: string]: string | undefined;
    };
    pathname: string;
    meta: MetaDescriptor[];
    data: {
        path: string;
    };
    handle?: unknown;
    error?: unknown;
}, {
    id: "routes/home";
    params: {} & {
        [key: string]: string | undefined;
    };
    pathname: string;
    meta: MetaDescriptor[];
    data: {
        name: string;
    };
    handle?: unknown;
    error?: unknown;
}, ...({
    id: unknown;
    params: unknown;
    pathname: string;
    meta: MetaDescriptor[];
    data: unknown;
    handle?: unknown;
    error?: unknown;
} | undefined)[]]
@tobigumo tobigumo added the bug label Feb 5, 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

1 participant