I'm trying to define a generic type for a component and I want to allow only the keys of an object for the name property of MySubInterface.
The issue I'm facing is that the type the interface receive is an array of Objects. I've tried to use something like
name: Keys[number]
But the result is an error "Type 'number' cannot be used to index type 'Keys'".
The type is something like this
unique symbol | keyof { email: string; type: EmailType; isPrimary: boolean; }[]
and these are a sample of the interfaces
interface MyInterface<T, Key extends keyof T>{
inputs: MySubInterface<T[Key], keyof T[Key]>[];
name?: Key;
}
interface MySubInterface<T, Keys>{
name: Keys
component: (props: ComponentOptions<T>) => ReactNode
}
Some idea on how to get the list of keys in this case? Thanks