I have found the concept of combining enums with namespaces to be incredibly valuable. For instance, consider the following:
enum Status : {
OK = 1,
NOT_OK = 2,
}
namespace Status {
function Color(status : Status) {
if(status == Status.OK)
return 'green';
else
return 'red';
}
}
However, I have come to realize that tslint does not approve of this approach... What alternatives could I explore to achieve similar functionality? One idea I had was to replace the namespace with a class containing static methods, but this presents two challenges:
1) The class would need to have a different name (such as 'StatusUtil') - which is a minor inconvenience.
2) Unlike namespaces, the 'StatusUtil' class cannot be directly accessed from an HTML file in an Angular application - necessitating the inclusion of additional methods in each component, like so:
getColor(status : Status) {
return StatusUtil(status);
}
Another possibility I considered was leveraging Angular's dependency injection instead of static methods. What approach do you think would be the most effective in this scenario?