[react-router] add string[] to matchPath and useRouteMatch arg types (#39037)

This commit is contained in:
Cina Saffary
2019-10-14 13:03:38 -07:00
committed by Andrew Branch
parent b18bc628f8
commit 2d75b571cf
2 changed files with 4 additions and 3 deletions
+2 -2
View File
@@ -127,7 +127,7 @@ export interface match<Params extends { [K in keyof Params]?: string } = {}> {
// Omit taken from https://github.com/Microsoft/TypeScript/issues/28339#issuecomment-467220238
export type Omit<T, K extends keyof T> = T extends any ? Pick<T, Exclude<keyof T, K>> : never;
export function matchPath<Params extends { [K in keyof Params]?: string }>(pathname: string, props: string | RouteProps, parent?: match<Params> | null): match<Params> | null;
export function matchPath<Params extends { [K in keyof Params]?: string }>(pathname: string, props: string | string[] | RouteProps, parent?: match<Params> | null): match<Params> | null;
export function generatePath(pattern: string, params?: { [paramName: string]: string | number | boolean | undefined }): string;
@@ -156,5 +156,5 @@ export function useLocation<S = H.LocationState>(): H.Location<S>;
export function useParams<Params extends { [K in keyof Params]?: string } = {}>(): { [p in keyof Params]: string };
export function useRouteMatch<Params extends { [K in keyof Params]?: string } = {}>(
path?: string | RouteProps,
path?: string | string[] | RouteProps,
): match<Params> | null;
+2 -1
View File
@@ -15,7 +15,8 @@ const HooksTest: React.FC = () => {
const { id } = useParams();
const params = useParams<Params>();
const match1 = useRouteMatch<Params>('/:id');
const match2 = useRouteMatch<Params>({ path: '/:id', exact: true });
const match2 = useRouteMatch<Params>(['/one/:id', '/two/:id']);
const match3 = useRouteMatch<Params>({ path: '/:id', exact: true });
history.location.state.s;
location.state.s;