[Solved] Typescript typegoose getModelForClass return type

Simon Verhoeven Asks: Typescript typegoose getModelForClass return type
Using typegoose/mongoose I can get the Model for a Class like this (where Clip is some class that will be saved to db)

Code:
import { getModelForClass } from '@typegoose/typegoose';
...

const ClipModel = getModelForClass(Clip);

And this Model is constructible, by this I mean I can do this;

Code:
const clip = new ClipModel()
const clip = new ClipModel({someProp: "someValue"})

Questions​

  1. How is this possible. If I look at the return type of getModelForClass here it is ReturnModelType<U, QueryHelpers> so how can a type have a constructor? Is this not the same as doing;

Code:
const clip = new ReturnModelType<Clip, QueryHelpers>(); // Ts error: 'ReturnModelType' only refers to a type, but is being used as a value here.

  1. IF ClipModel can be constructed does this mean that ClipModel is a class? If it is it should be possible to do this right?

Code:
class MyCustomModel extends ClipModel {
 // Add some customisations 
}

However, this give a ts error Base constructors must all have the same return type.

  1. Is it possible to extend ClipModel to have some custom functions on it so it can be called like;

Code:
ClipModel.find({}) // the default created find method 
ClipModel.myCustomFind({}) // find method with custom stuff

Thanks,

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.