For example, I have a class Module and many classes will inherit from it. For example, the User module or the Session module, and I want to store all these classes in one place.

class User extends Module { } api.addModule(User) 

How do I describe the type of argument taken by the addModule function?

 addModule (moduleClass:Function){ this.modules[moduleClass.name] = moduleClass } 

moduleClass: Function ??? Fankshen works, but I do not need any functions, namely classes, and even inherited from Module

moreover I want to create the addModules function

 api.addModules([User, Session]) 

so that you can take an array of classes =) tell me how to describe such a parameter in the typescript? so that no matter how instanced a class is, namely the class itself or its classes are heirs.

    1 answer 1

    To indicate that we need not an instance of the class, but the class itself, the following construction is used: typeof Class

     addModule(ModuleClass:typeof Module) { this.modules[module.name] = ModuleClass } getModule(name:string):typeof Module { return this.modules[name] } addModules(modules:typeof Module[]) { } 

    My mistake was that I used an outdated typeof (Module) type syntax that I used to talk about the developers of the typing script that they had in 2012 ^ _ ^