mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 02:59:04 +08:00
chore(TS): add comments to TS type methods (#49224)
This commit is contained in:
parent
526d8ba0c2
commit
e7d7a0b3cd
@ -7,6 +7,17 @@ export type AnyObject = Record<PropertyKey, any>;
|
||||
|
||||
export type CustomComponent<P = AnyObject> = React.ComponentType<P> | string;
|
||||
|
||||
/**
|
||||
* Get component props
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Checkbox } from 'antd'
|
||||
* import type { GetProps } from 'antd';
|
||||
*
|
||||
* type CheckboxGroupProps = GetProps<typeof Checkbox.Group>
|
||||
* ```
|
||||
* @since 5.13.0
|
||||
*/
|
||||
export type GetProps<T extends React.ComponentType<any> | object> = T extends React.ComponentType<
|
||||
infer P
|
||||
>
|
||||
@ -15,6 +26,23 @@ export type GetProps<T extends React.ComponentType<any> | 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<SelectProps, 'options'>[number];
|
||||
* // or
|
||||
* type SelectOption2 = GetProp<typeof Select, 'options'>[number];
|
||||
*
|
||||
* const onChange: GetProp<typeof Select, 'onChange'> = (value, option) => {
|
||||
* // Do something
|
||||
* };
|
||||
* ```
|
||||
* @since 5.13.0
|
||||
*/
|
||||
export type GetProp<
|
||||
T extends React.ComponentType<any> | object,
|
||||
PropName extends keyof GetProps<T>,
|
||||
@ -26,6 +54,17 @@ type ReactRefComponent<Props extends { ref?: React.Ref<any> | string }> = (
|
||||
|
||||
type ExtractRefAttributesRef<T> = T extends React.RefAttributes<infer P> ? P : never;
|
||||
|
||||
/**
|
||||
* Get component ref
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Input } from 'antd';
|
||||
* import type { GetRef } from 'antd';
|
||||
*
|
||||
* type InputRef = GetRef<typeof Input>;
|
||||
* ```
|
||||
* @since 5.13.0
|
||||
*/
|
||||
export type GetRef<T extends ReactRefComponent<any> | React.Component<any>> =
|
||||
T extends React.Component<any>
|
||||
? T
|
||||
|
Loading…
Reference in New Issue
Block a user