Skip to main content
Clarified intended behavior on title and explanation
Source Link
Erick Petrucelli
  • 15.1k
  • 9
  • 68
  • 89

use Use object in typescriptliteral as TypeScript enum values

I have aan enum  :

 export enum PizzaSize {
          SMALL =  0,
          MEDIUM = 1,
          LARGE = 2
    
    }
export enum PizzaSize {
  SMALL =  0,
  MEDIUM = 1,
  LARGE = 2
}

But here I wouldI'd like to use some pair of values: e.g. SMALL iSMALL I would like to say that it has 2 valuesa (0, 100)key of 0 and a value of 100. How can I do this one?

I endeavor to use:

export enum PizzaSize {
          SMALL =  {key:key, value: value},
         ...

    }
export enum PizzaSize {
  SMALL =  { key: 0, value: 100 },
  // ...
}

But typescriptTypeScript doesn't accept this one. How can I do this?

use object in typescript enum

I have a enum  :

 export enum PizzaSize {
          SMALL =  0,
          MEDIUM = 1,
          LARGE = 2
    
    }

But here I would like to use some pair of values: e.g. SMALL i would like to say that it has 2 values (0, 100). How can I do this one?

I endeavor to use

export enum PizzaSize {
          SMALL =  {key:key, value: value},
         ...

    }

But typescript doesn't accept this one.

Use object literal as TypeScript enum values

I have an enum:

export enum PizzaSize {
  SMALL =  0,
  MEDIUM = 1,
  LARGE = 2
}

But here I'd like to use some pair of values: e.g. SMALL I would like to say that it has a key of 0 and a value of 100. I endeavor to use:

export enum PizzaSize {
  SMALL =  { key: 0, value: 100 },
  // ...
}

But TypeScript doesn't accept this one. How can I do this?

question was more related to typescript than angular 2
Source Link
n00dl3
  • 21.6k
  • 8
  • 70
  • 77

use object in typescript enum class of ANgular2

I have a enum :

 export enum PizzaSize {
          SMALL =  0,
          MEDIUM = 1,
          LARGE = 2
    
    }

But here I would like to use some pair of values: e.g. SMALL i would like to say that it has 2 values (0, 100). How can I do this one?

I endeavor to use

export enum PizzaSize {
          SMALL =  {key:key, value: value},
         ...

    }

But Angular2typescript doesn't accept this one.

use object in enum class of ANgular2

I have a enum :

 export enum PizzaSize {
          SMALL =  0,
          MEDIUM = 1,
          LARGE = 2
    
    }

But here I would like to use some pair of values: e.g. SMALL i would like to say that it has 2 values (0, 100). How can I do this one?

I endeavor to use

export enum PizzaSize {
          SMALL =  {key:key, value: value},
         ...

    }

But Angular2 doesn't accept this one.

use object in typescript enum

I have a enum :

 export enum PizzaSize {
          SMALL =  0,
          MEDIUM = 1,
          LARGE = 2
    
    }

But here I would like to use some pair of values: e.g. SMALL i would like to say that it has 2 values (0, 100). How can I do this one?

I endeavor to use

export enum PizzaSize {
          SMALL =  {key:key, value: value},
         ...

    }

But typescript doesn't accept this one.

Source Link
Vahe Akhsakhalyan
  • 2.2k
  • 4
  • 26
  • 41

use object in enum class of ANgular2

I have a enum :

 export enum PizzaSize {
          SMALL =  0,
          MEDIUM = 1,
          LARGE = 2
    
    }

But here I would like to use some pair of values: e.g. SMALL i would like to say that it has 2 values (0, 100). How can I do this one?

I endeavor to use

export enum PizzaSize {
          SMALL =  {key:key, value: value},
         ...

    }

But Angular2 doesn't accept this one.