Imagine you have this custom class:
export class PerformActionClass<TEntity> {
constructor(entity: TEntity) {
}
}
You can use it in your code like this:
new PerformActionClass<Person>(myPersonObject);
However, you may want a more concise way of calling it:
PerformAction<Person>(myPersonObject);
This shorthand syntax is achievable with the following approach:
export function PerformAction<TEntity>(entity: TEntity): PerformActionClass<TEntity>{
return new PerformActionClass<TEntity>(entity);
}
The desired goal is to export the constructor of the class as a separate, named function without duplication. One attempt was:
export PerformAction = PerformActionClass.prototype.constructor;
Unfortunately, this method did not work as expected. Is there a more efficient way to accomplish this task?