If I need to use const variables I use this approach since it has a type safety.
export class LocalStorage {
static USER_INFO = "user-info";
static PROFILE_INFO = "profile-info";
}
But it seems we can use string enums
like so:
export enum LocalStorage {
USER_INFO = "user-info";
PROFILE_INFO = "profile-info";
}
What is the difference between these 2 approaches?
enum is logical grouping of your constants. Let's say you want to use different color. Then you make color enum consist of all colors value defined. Lets say accountType which consist value of current, saving, loan, recurring. Its logical grouping. Constant you can define for anything.
Now you have to make sure that your enum name has anything to do with logical grouping?
In Your case Enum name is LocalStorage but values underneath does not justify as enum