I'm trying to figure out how to create an object based on a generic type in TypeScript but struggling with the syntax. Here's a simplified example of what I want to achieve:
myfunc<T>() : T[] {
let obj = new T();
let obj2 = new T();
return [obj, obj2];
}
The new T()
doesn't compile as expected. In C#, I would use a where T : new
constraint to resolve this issue. Can someone help me understand how to do the equivalent in TypeScript?