As I continue to explore different coding styles in Typescript and Angular, I recently encountered a method without any comments attached to it.
It seems like this method is enforcing that the value passed in must be one of the defined options, but strangely, it does not utilize ENUM for enforcement. This lack of documentation could potentially cause issues in a large codebase.
Is my understanding correct that this method requires the value to be equal to one of the || options?
static getEndpoint = (type: string = 'alpha' || 'bravo' || 'charlie) => {}
In my opinion, utilizing an ENUM would have been a better approach:
export enum MyTypes {
ALPHA = 'alpha',
BRAVO = 'bravo',
CHARLIE = 'charlie',
}
And then modifying the method like this:
static getEndpoint = (type: MyTypes = MyTypes.ALPHA) => {}