'Declaring namespaces with same name as Enum throws a Sonar issue [Angular]

THE SOURCE OF ERROR

In my code I have:

export enum MobileType {
    APPLE = 'iphone',
    XIAOMI = 'xiami',
    WINDOWS_PHONE = 'wp',
    NOKIA = 'nokia',
}

export namespace MobileType {
    export function isAppleMobile(mobileInfo: MobileInfo): boolean {
        return mobileInfo.type === MobileType.APPLE
    }
}

I find the use of namespaces convenient, since in the code it allows you to group enums and its related util functions:

export class MobileService {
    getAllApple(): MobileInfo[] {
        return this.mobiles.filter(mobile => MobileType.isAppleMobile(mobile.type))
    } 
}

However Sonar Qube throws an error:

This rule checks that a declaration doesn't use a name that is already in use. Indeed, it is possible to use the same symbol multiple times as either a variable or a function, but doing so is likely to confuse maintainers. Further it's possible that such reassignments are made in error, with the developer not realizing that the value of the variable is overwritten by the new assignment.

SOLUTION I AM LOOKING FOR

Can you advice some Angular good practice on how to group those helper functions in relation to the enum?

I have though of using a service but I don't like the hassle of providing a whole service in a class constructor just to access some static utility functions. Would a ts class be the best alternative?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source