Skip to content

Commit

Permalink
Use union and intersection to remove property duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Aug 17, 2021
1 parent 46db4e5 commit 382e340
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions js/src/common/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ export type RouteItem<
Attrs extends ComponentAttrs,
Comp extends Component<Attrs & { routeName: string }>,
RouteArgs extends Record<string, unknown> = {}
> =
> = {
/**
* The path for your route.
*
* This might be a specific URL path (e.g.,`/myPage`), or it might
* contain a variable used by a resolver (e.g., `/myPage/:id`).
*
* @see https://docs.flarum.org/extend/frontend-pages.html#route-resolvers-advanced
*/
path: `/${string}`;
} & (
| {
/**
* The path for your route.
*
* This might be a specific URL path (e.g.,`/myPage`), or it might
* contain a variable used by a resolver (e.g., `/myPage/:id`).
*
* @see https://docs.flarum.org/extend/frontend-pages.html#route-resolvers-advanced
*/
path: `/${string}`;
/**
* The component to render when this route matches.
*/
Expand All @@ -60,20 +61,12 @@ export type RouteItem<
resolverClass?: { new (): DefaultResolver<Attrs, Comp, RouteArgs> };
}
| {
/**
* The path for your route.
*
* This might be a specific URL path (e.g.,`/myPage`), or it might
* contain a variable used by a resolver (e.g., `/myPage/:id`).
*
* @see https://docs.flarum.org/extend/frontend-pages.html#route-resolvers-advanced
*/
path: `/${string}`;
/**
* An instance of a route resolver.
*/
resolver: RouteResolver<Attrs, Comp, RouteArgs>;
};
}
);

export interface RouteResolver<
Attrs extends ComponentAttrs,
Expand Down

0 comments on commit 382e340

Please sign in to comment.