0

How my structure looks like ?

namespace DataProviders
{
     export function SomeExportFunction<T>(myConstructor: { new (): T; MappingOptions?: any; }): T[]
    {
        //getting "SomeClass" as a string from "someModuleOrNameSpace.SomeClass" which should be somewhere in "myConstructor"(parameter)
    }
}       

How to use ? this.Something=SomeNamespace.SomeExportFunction(someModuleOrNameSpace.SomeClass);

I tried myConstructor.constructor.toString().match(/\w+/g)[1]; this will return Function, bit I need SomeClass.

Based on this post Get an object's class name at runtime in TypeScript.

So how can I get the class name of myConstructor ?

Community
  • 1
  • 1
user7425470
  • 735
  • 1
  • 6
  • 13

1 Answers1

1

It's exactly the same as in the thread you linked to, with one exception which is that you want the name from the class instead of the instance.
So this:

myConstructor.constructor.toString().match(/\w+/g)[1];

Should be:

myConstructor.toString().match(/\w+/g)[1];

If myConstructor was an instance then myConstructor.constructor would have been the class. In your case this step is reduandent.

Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299