Huject icon indicating copy to clipboard operation
Huject copied to clipboard

Enum Support?

Open pyrossh opened this issue 8 years ago • 1 comments

I would like to register a service using an enum value. But currently its not possible.

enum Property {
   APIEndpoint
   APIVersion
   TaxRate
}

const engine = new Container()
engine.register(Property.TaxRate, 14.0)

pyrossh avatar Oct 04 '16 04:10 pyrossh

The problem is that typescript enums are number based. Consider following:

enum First {
   FIRST,
   SECOND
}

enum Second {
   SecondFirst,
   SecondSecond
}

engine.register(First.FIRST, 10);
engine.register(Second.SecondFirst, 15);

engine.resolve(First.FIRST); // 15

There is nothing to prevent you accidentally overwrite first enum value. I'd use es6 Symbol or string literal types for that instead.

asvetliakov avatar Nov 06 '16 23:11 asvetliakov