How to know if incoming variable is of a specific enum type?

So, can anyone tell me how I can get to know when my input argument is of a specific enum type?

It's not possible. Look at the compiled code for the enum:

TypeScript:

enum PersonType { Type1, Type2 }

JavaScript:

var PersonType;
(function (PersonType) {
    PersonType[PersonType["Type1"] = 0] = "Type1";
    PersonType[PersonType["Type2"] = 1] = "Type2";
})(PersonType || (PersonType = {}));

At runtime, the enum PersonType is just a JavaScript object used as a map. Its members are strings and numbers. The enumeration of your example contains:

{
  "Type1": 0,
  "Type2": 1,
  "0": "Type1",
  "1": "Type2"
}

So, the members Type1 and Type2 in the enumeration, are true numbers:

console.log(PersonType.Type1) // 0

Tags:

Typescript