My Route
interface has a params
object, and I'm looking to ensure type safety on that params object. For example:
If we have a route config like this:
{
post: {
path: 'posts/:id',
}
}
navigate({ name: 'post', params: { wrongKey: '1' } });
I've defined the Route
interface as shown below, but T[keyof T]
doesn't seem to correctly infer which key it is:
type Route<T extends Config> = {
hash?: string;
name: keyof T & string;
params?: RouteParams<T[keyof T]['path']>;
search?: Record<string, string>;
};
I want this scenario to raise an error because wrongKey
should be id
. Currently, all I get are param keys as types of string
.
You can check out the full code in the playground link here.