classIdleService{doNothing():void{}}classNews{title: string;content: string;constructor(title: string,content: string){this.title=title;this.content=content;}}constinstanceCounter: Map<Function,number>=newMap();interfaceConstructor{new(...arguments_: any[]):any;}// Keep track how many instances of `Constr` constructor have been created.functiongetInstance<ConstrextendsConstructor,ArgumentsextendsConstructorParameters<Constr>>(constructor:Constr,...arguments_: Arguments):InstanceType<Constr>{letcount=instanceCounter.get(constructor)||0;constinstance=newconstructor(...arguments_);instanceCounter.set(constructor,count+1);console.log(`Created ${count+1} instances of ${Constr.name} class`);returninstance;}constidleService=getInstance(IdleService);// Will log: `Created 1 instances of IdleService class`constnewsEntry=getInstance(News,"New ECMAScript proposals!","Last month...");// Will log: `Created 1 instances of News class`