0

How to create a Class based on given String?

I tried this code but it doesn't work.

public create(className: string): ISports {
   // className = "Baseball";
   return new global[className]();
}

I keep getting this error.

Element implicitly has an 'any' type because type 'Global' has no index signature.

Steven
  • 821
  • 1
  • 10
  • 24

0 Answers0