From e7d7a0b3cd7d4d47ecbff96a9b01d0b7b2a10fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2?= Date: Tue, 4 Jun 2024 21:00:20 +0800 Subject: [PATCH] chore(TS): add comments to TS type methods (#49224) --- components/_util/type.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/components/_util/type.ts b/components/_util/type.ts index 074ebdc7a4..37b107729e 100644 --- a/components/_util/type.ts +++ b/components/_util/type.ts @@ -7,6 +7,17 @@ export type AnyObject = Record; export type CustomComponent

= React.ComponentType

| string; +/** + * Get component props + * @example + * ```ts + * import { Checkbox } from 'antd' + * import type { GetProps } from 'antd'; + * + * type CheckboxGroupProps = GetProps + * ``` + * @since 5.13.0 + */ export type GetProps | object> = T extends React.ComponentType< infer P > @@ -15,6 +26,23 @@ export type GetProps | object> = T extends Re ? T : never; +/** + * Get component props by component name + * @example + * ```ts + * import { Select } from 'antd'; + * import type { GetProp, SelectProps } from 'antd'; + * + * type SelectOption1 = GetProp[number]; + * // or + * type SelectOption2 = GetProp[number]; + * + * const onChange: GetProp = (value, option) => { + * // Do something + * }; + * ``` + * @since 5.13.0 + */ export type GetProp< T extends React.ComponentType | object, PropName extends keyof GetProps, @@ -26,6 +54,17 @@ type ReactRefComponent | string }> = ( type ExtractRefAttributesRef = T extends React.RefAttributes ? P : never; +/** + * Get component ref + * @example + * ```ts + * import { Input } from 'antd'; + * import type { GetRef } from 'antd'; + * + * type InputRef = GetRef; + * ``` + * @since 5.13.0 + */ export type GetRef | React.Component> = T extends React.Component ? T