-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Closed
Description
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.14Used 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)[]]
HendrikSchmidt and jenseo