I have this in my typings file:
declare namespace Somatic {
enum PropType {
html,
object,
css
}
}
In another file index.ts, I have a shorter alias for this enum as:
type PropType = Somatic.PropType;
Then I want to use the aliased enum type in a switch statement:
switch (propType) {
case PropType.html:
break;
.
.
.
}
But Typescript does not recognize the aliased enum type values. What is wrong here?
You should use import
keyword instead of type
:
import PropType = Somatic.PropType;
More info on import alias declarations here.
** This syntax won't work if you're using babel-plugin-transform-typescript because this is typescript only form of import. Generally using namespaces is not recommended.
In typescript, an enum is both a type and a map. You should alias the type and the map separately:
type PropTypeEnum = Somatic.PropType;
const PropType = Somatic.PropType;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With