From 8a230505b82615c53cf6b45c28c9bf58378bc014 Mon Sep 17 00:00:00 2001 From: ice <49827327+coding-ice@users.noreply.github.com> Date: Fri, 16 Aug 2024 23:39:46 +0800 Subject: [PATCH] type(tag): Optimize ts types (#50427) --- components/_util/hooks/useClosable.tsx | 8 +++++--- components/tag/index.tsx | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/components/_util/hooks/useClosable.tsx b/components/_util/hooks/useClosable.tsx index f917221ffe..281eb4dbf8 100644 --- a/components/_util/hooks/useClosable.tsx +++ b/components/_util/hooks/useClosable.tsx @@ -6,10 +6,12 @@ import pickAttrs from 'rc-util/lib/pickAttrs'; export type BaseClosableType = { closeIcon?: React.ReactNode } & React.AriaAttributes; export type ClosableType = boolean | BaseClosableType; -export type ContextClosable = - Partial>; +export type BaseContextClosable = { closable?: ClosableType; closeIcon?: ReactNode }; +export type ContextClosable = Partial< + Pick +>; -export function pickClosable( +export function pickClosable( context?: ContextClosable, ): ContextClosable | undefined { if (!context) { diff --git a/components/tag/index.tsx b/components/tag/index.tsx index 4a062b0a26..30849c63f8 100644 --- a/components/tag/index.tsx +++ b/components/tag/index.tsx @@ -4,6 +4,7 @@ import omit from 'rc-util/lib/omit'; import type { PresetColorType, PresetStatusColorType } from '../_util/colors'; import { isPresetColor, isPresetStatusColor } from '../_util/colors'; +import type { ClosableType } from '../_util/hooks/useClosable'; import useClosable, { pickClosable } from '../_util/hooks/useClosable'; import { replaceElement } from '../_util/reactNode'; import type { LiteralUnion } from '../_util/type'; @@ -22,8 +23,8 @@ export interface TagProps extends React.HTMLAttributes { className?: string; rootClassName?: string; color?: LiteralUnion; - closable?: boolean | ({ closeIcon?: React.ReactNode } & React.AriaAttributes); /** Advised to use closeIcon instead. */ + closable?: ClosableType; closeIcon?: React.ReactNode; /** @deprecated `visible` will be removed in next major version. */ visible?: boolean;