Is it possible to somehow specify the generic parameters of a generic type?
I am trying to create a fully typed api url builder, which will set correct types on my data models based on the specified options for the url.
I have a class
class ApiUrlBuilder<M extends ApiModel>
which has an embed()
method:
embed<T extends keyof ApiModelEmbeds<M> |(keyof ApiModelEmbeds<M>)[]>(fields: T):
ApiUrlBuilder<ApiModel<ApiModelAttributes<M>, PickAndNullifyOthers<ApiModelEmbeds<M>, T extends any[] ? T[number] : T>>> {
And this basically does what I want it to do, however, my data models usually extend the base model (adding custom getters, methods etc.) and this information is currently lost in my implementation.
How could I change the generic types of the model and retain the information about the specific class? Something like M<ApiModelAttributes<M>, PickAndNullifyOthers<ApiModelEmbeds<M>, T extends any[] ? T[number] : T>>