Skip to content

Commit 23e0d89

Browse files
Add example with Pick
1 parent df15810 commit 23e0d89

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

docs/react-types/ComponentProps.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: ComponentProps<T>
2+
title: ComponentProps<Element>
33
---
44

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.
66

77
:::note
88

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.
1010

1111
:::
1212

@@ -20,7 +20,7 @@ Prefer `ComponentPropsWithRef<T>` if ref is forwarded and `ComponentPropsWithout
2020

2121
### Getting all valid props of an element
2222

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.
2424

2525
```tsx
2626
interface Props extends ComponentProps<"div"> {
@@ -63,5 +63,14 @@ However, this type if not really reflecting the actual set of icons made availab
6363
import { Icon } from "component-library";
6464

6565
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"
6776
```

0 commit comments

Comments
 (0)