From 1108f1cd17fc41cc468163f5f5eadabb5d8c7124 Mon Sep 17 00:00:00 2001 From: ppbl <33046279+ppbl@users.noreply.github.com> Date: Fri, 3 Dec 2021 05:59:36 +0800 Subject: [PATCH] Improve the type of useParams (#8352) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 侯宗楠 --- packages/react-router/index.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/react-router/index.tsx b/packages/react-router/index.tsx index 4bf872a0a5..c12b300d07 100644 --- a/packages/react-router/index.tsx +++ b/packages/react-router/index.tsx @@ -526,8 +526,10 @@ export function useOutlet(): React.ReactElement | null { * * @see https://reactrouter.com/docs/en/v6/api#useparams */ -export function useParams(): Readonly< - Params +export function useParams< + ParamsOrKey extends string | Record = string +>(): Readonly< + [ParamsOrKey] extends [string] ? Params : Partial > { let { matches } = React.useContext(RouteContext); let routeMatch = matches[matches.length - 1];