I'm currently creating versatile methods for use across various frontend applications. The goal is to invoke the function
.postAsync<CustomModel>('www.mysite.com',..., CustomModel);
and receive a CustomModel object as the response.
I want to establish a default value for the second parameter, making it a different model by default, but allowing for customization when necessary.
How can I define a default value for an argument of type Constructable<T>
, where the Constructable interface is defined as:
interface Constructable<T> { new(params: any): T; }
I've attempted setting default values for an interface with different argument types, but encountered the error
Type Constructable<CustomModel> is not assignable to type Constructable<T>
. I've also tried setting T to CustomModel in the generic method and encountered the same error.
The expectation was that I wouldn't need to specify a model when calling the postAsync()
method and that it would always return a CustomModel object. However, I received the error
Type Constructable<CustomModel> is not assignable to type Constructable<T>
.