1
1
---
2
- title : ComponentProps<T >
2
+ title : ComponentProps<Element >
3
3
---
4
4
5
- ` ComponentProps<T > ` is a utility type that lets you grab all valid props of an element, or infer prop type of a component.
5
+ ` ComponentProps<Element > ` is a utility type that lets you grab all valid props of an element, or infer prop type of a component.
6
6
7
7
::: note
8
8
9
- Prefer ` ComponentPropsWithRef<T > ` if ref is forwarded and ` ComponentPropsWithoutRef<T > ` when ref is not forwarded.
9
+ Prefer ` ComponentPropsWithRef<Element > ` if ref is forwarded and ` ComponentPropsWithoutRef<Element > ` when ref is not forwarded.
10
10
11
11
:::
12
12
@@ -20,7 +20,7 @@ Prefer `ComponentPropsWithRef<T>` if ref is forwarded and `ComponentPropsWithout
20
20
21
21
### Getting all valid props of an element
22
22
23
- ` ComponentProps<T > ` can be used to create a type that includes all valid ` div ` props.
23
+ ` ComponentProps<Element > ` can be used to create a type that includes all valid ` div ` props.
24
24
25
25
``` tsx
26
26
interface Props extends ComponentProps <" div" > {
@@ -63,5 +63,14 @@ However, this type if not really reflecting the actual set of icons made availab
63
63
import { Icon } from " component-library" ;
64
64
65
65
type IconName = ComponentProps <typeof Icon >[" name" ];
66
- // ^? type IconName = "warning" | "checkmark" | ...
66
+ // ^? type IconName = "warning" | "checkmark"
67
+ ```
68
+
69
+ You can also use the ` Pick<Type, Keys> ` utility type to accomplish the same thing:
70
+
71
+ ``` tsx
72
+ import { Icon } from " component-library" ;
73
+
74
+ type IconName = Pick <ComponentProps <typeof Icon >, " name" >;
75
+ // ^? type IconName = "warning" | "checkmark"
67
76
```
0 commit comments