2024-03-21 15:55:40 +08:00
|
|
|
---
|
|
|
|
category: Components
|
|
|
|
title: Util
|
2024-03-22 14:22:42 +08:00
|
|
|
description: Utilities are used to assist development and provide some common utility methods.
|
|
|
|
showImport: false
|
2024-03-21 15:55:40 +08:00
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*rRDlT7ST8DUAAAAAAAAAAAAADrJ8AQ/original
|
|
|
|
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*rRDlT7ST8DUAAAAAAAAAAAAADrJ8AQ/original
|
2024-04-02 14:05:03 +08:00
|
|
|
tag: 5.13.0
|
2024-03-21 15:55:40 +08:00
|
|
|
demo:
|
|
|
|
cols: 2
|
|
|
|
group:
|
|
|
|
title: Other
|
|
|
|
order: 99
|
|
|
|
---
|
|
|
|
|
2024-04-02 14:05:03 +08:00
|
|
|
Available since `5.13.0`.
|
|
|
|
|
2024-03-21 15:55:40 +08:00
|
|
|
## GetRef
|
|
|
|
|
|
|
|
Get the `ref` property definition of the component, which is very useful for components that are not directly exposed or child components.
|
|
|
|
|
|
|
|
```tsx
|
2024-04-02 14:05:03 +08:00
|
|
|
import { Select } from 'antd';
|
|
|
|
import type { GetRef } from 'antd';
|
2024-03-21 15:55:40 +08:00
|
|
|
|
|
|
|
type SelectRefType = GetRef<typeof Select>; // BaseSelectRef
|
|
|
|
```
|
|
|
|
|
|
|
|
## GetProps
|
|
|
|
|
|
|
|
Get the `props` property definition of the component:
|
|
|
|
|
|
|
|
```tsx
|
2024-04-02 14:05:03 +08:00
|
|
|
import { Checkbox } from 'antd';
|
|
|
|
import type { GetProps } from 'antd';
|
2024-03-21 15:55:40 +08:00
|
|
|
|
|
|
|
type CheckboxGroupType = GetProps<typeof Checkbox.Group>;
|
|
|
|
```
|
|
|
|
|
|
|
|
## GetProp
|
|
|
|
|
2024-04-11 12:09:37 +08:00
|
|
|
Get the single `props` property definition of the component. It has encapsulated `NonNullable`, so you don't have to worry about it being empty:
|
2024-03-21 15:55:40 +08:00
|
|
|
|
|
|
|
```tsx
|
2024-04-02 14:05:03 +08:00
|
|
|
import { Select } from 'antd';
|
|
|
|
import type { GetProp, SelectProps } from 'antd';
|
2024-03-21 15:55:40 +08:00
|
|
|
|
2024-04-11 12:09:37 +08:00
|
|
|
// Both of these can work
|
2024-03-21 15:55:40 +08:00
|
|
|
type SelectOptionType1 = GetProp<SelectProps, 'options'>[number];
|
|
|
|
type SelectOptionType2 = GetProp<typeof Select, 'options'>[number];
|
|
|
|
```
|