Generic type besides generic component #10372
Unanswered
matheusjv11
asked this question in
Help/Questions
Replies: 2 comments
-
const some_key = ref<MyType>({}); |
Beta Was this translation helpful? Give feedback.
0 replies
-
Just add another prop containing a value of the underlying type. The keyof T prop will be type-checked. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a select component which I recieve a fieldEnum as some of the props. Today it expect only a string.
As I'm going to use this component for some different forms, each of them will have different field enums that composes its object. My idea is pass a generic type that would only be used to define what values fieldEnum can be. It would look something like this:
Where somehow on my parent component, I would define the T type. This way, whenever I set something on fieldEnum, ts would force me to use only the existing keys from the given Type.
<FormSelectInput<MyType> field-enum="some_key" label="Fancy Select" />
I know that there are some workarounds, such as creating proxy components for each form that can import the select props and require the specific enum. But I'm seeking for a less-code solution. I would be glad if someone could help me on this.
Beta Was this translation helpful? Give feedback.
All reactions