Skip to content

Commit

Permalink
Remove TParams type parameter in favor of Record<string, string>
Browse files Browse the repository at this point in the history
Having TParams as type parameter assignable to Record<string, string>
with default Record<string, string> causes issues when passing specific
params since an interface with specific keys is not assignable to a
Record which can have any key:
  Index signature is missing in type 'ParamsInterface'.
So, for now we will make `params` always be a Record<string, string>.
  • Loading branch information
kyarik committed Dec 21, 2020
1 parent ba5581f commit 0489e5e
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ export interface Match {
params: Record<string, string>;
}

export interface RouteComponentProps<
TPreloadedData = any,
TParams extends Record<string, string> = Record<string, string>
> {
export interface RouteComponentProps<TPreloadedData = any> {
/**
* The preloaded data returned by `preloadData`. If `preloadData` is not
* specified for a route, then `preloadedData` is `undefined`.
Expand All @@ -24,23 +21,19 @@ export interface RouteComponentProps<
/**
* The values of the dynamic parameters in the `path`, if any.
*/
params: TParams;
params: Record<string, string>;

/**
* Any matching child routes that should be rendered inside the parent route.
*/
children: ReactNode;
}

export type RouteComponent<
TPreloadedData = any,
TParams extends Record<string, string> = Record<string, string>
> = ComponentType<RouteComponentProps<TPreloadedData, TParams>>;
export type RouteComponent<TPreloadedData = any> = ComponentType<
RouteComponentProps<TPreloadedData>
>;

export type Route<
TPreloadedData = any,
TParams extends Record<string, string> = Record<string, string>
> = {
export type Route<TPreloadedData = any> = {
/**
* The path for which this route will match. Path parameters, even with
* custom regular expressions, are supported.
Expand All @@ -50,15 +43,15 @@ export type Route<
/**
* The component to render for the route.
*/
component: RouteComponent<TPreloadedData, TParams>;
component: RouteComponent<TPreloadedData>;

/**
* Function used to preload data for the route whenever it matches. This
* function is called with the route parameters and it should return the
* preloaded data in the form of a resource that the route component can
* attempt to read and if it's not ready yet, the component suspends.
*/
preloadData?: (params: TParams) => TPreloadedData;
preloadData?: (params: Record<string, string>) => TPreloadedData;

/**
* The fallback component that will be shown while the component or data for
Expand All @@ -72,19 +65,13 @@ export type Route<
routes?: Route[];
};

export interface MatchedRoute<
TPreloadedData = any,
TParams extends Record<string, string> = Record<string, string>
> {
route: Route<TPreloadedData, TParams>;
export interface MatchedRoute<TPreloadedData = any> {
route: Route<TPreloadedData>;
match: Match;
}

export type PreloadedRoute<
TPreloadedData = any,
TParams extends Record<string, string> = Record<string, string>
> = {
component: RouteComponent<TPreloadedData, TParams>;
export type PreloadedRoute<TPreloadedData = any> = {
component: RouteComponent<TPreloadedData>;
preloadedData: TPreloadedData;
fallback?: ComponentType;
match: Match;
Expand Down

0 comments on commit 0489e5e

Please sign in to comment.