Home > Mobile >  Why computed values are not permitted in an enum?
Why computed values are not permitted in an enum?

Time:10-25

I am trying the keep route url's in an enum like below.

export enum RouteUrls {
HOME = '/home',
DASHBOARD = `${HOME}/dashboard` // error here 
}

In the above line I am getting error as "Computed values are not permitted in an enum with string valued members.", is there any other way to achieve the same using Enum in TypeScript.

CodePudding user response:

For now only numeric enums can have computed members. What you are trying to do is to have string enum with computed members, which is not permitted in TypeScript. I found that there is an open issue about this topic in official Microsoft TypeScript git repository. Maybe this feature will be implemented in the future versions.
URL to issue on git: https://github.com/microsoft/TypeScript/issues/40793

  • Related