I have a TypeScript Enum that lives within a different namespace to the file I am trying to use it in. The namespace for now unavoidable reasons is long and cumbersome to write
The project is not using modules and does not have a module loader so no imports or exports. My hands are tied here unfortunately. We bundle files manually.
enum Movement {
run,
walk
}
function Move(movement: App.System.User.Area.Movement) {
if (movement === App.System.User.Area.Movement.run) { //... }
//....
}
I am able to use it seems the type keyword to (and I am not sure this is the TypeScript word for it) type def that long namespace away.
type MovementType = App.System.User.Area.Movement;
function Move(movement: MovementType) {
if (movement === App.System.User.Area.Movement.run) { //... }
//....
}
But I cannot use that type def'd type in the equals comparison in my function above because "MovementType only refers to a type but is being used as a value here" when I try to do:
type MovementType = App.System.User.Area.Movement;
function Move(movement: MovementType) {
if (movement === MovementType.run) { //... }
//....
}
Is there any way to get around this? Why can't I use it in the conditional statement while I can have it as a parameter? How can I get around my very long namespace?
I am currently using TypeScript 3.1