I am looking to make a typescript generic of the Parameters
for a specific class.
type Example<T> = Parameters<UserRepository[T]>[0]
However I get this error:
Type 'T' cannot be used to index type "UserRepository"
also tried this:
type Example<T extends string> = Parameters<UserRepository[T]>[0]
I currently have this:
type Params = Parameters<UserRepository["members"]>[0] &
Parameters<UserRepository["contacts"]>[0] &
Parameters<UserRepository["user"]>[0]
I would like to create two generics ClassMethod
and ClassMethods
.
type ClassMethod<C, M> = string
type Param = ClassMethod<UserRepository, 'members'>
Or
type ClassMethod<T> = Parameters<UserRepository[T]>[0]
type Param = ClassMethod<'members'> // where the generic has `UserRepository `in it.
And
type ClassMethods<C, M> = string
type Params = ClassMethods<UserRepository, ['members', 'contacts', 'user']>