type(tag): Optimize ts types (#50427)

This commit is contained in:
ice 2024-08-16 23:39:46 +08:00 committed by GitHub
parent 7481e14dab
commit 8a230505b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -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<T extends { closable?: ClosableType; closeIcon?: ReactNode } = any> =
Partial<Pick<T, 'closable' | 'closeIcon'>>;
export type BaseContextClosable = { closable?: ClosableType; closeIcon?: ReactNode };
export type ContextClosable<T extends BaseContextClosable = any> = Partial<
Pick<T, 'closable' | 'closeIcon'>
>;
export function pickClosable<T extends { closable?: ClosableType; closeIcon?: ReactNode }>(
export function pickClosable<T extends BaseContextClosable>(
context?: ContextClosable<T>,
): ContextClosable<T> | undefined {
if (!context) {

View File

@ -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<HTMLSpanElement> {
className?: string;
rootClassName?: string;
color?: LiteralUnion<PresetColorType | PresetStatusColorType>;
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;