
Creating a TypeScript “non-enumerable” property decorator
Creating a TypeScript "non-enumerable" property decorator This post explains how to create a TypeScript property decorator that allows hiding a class property in enumerators. If you are new to TypeScript or it's decorators, you might start here first. Why should I be able to exclude a class property from being enumerated Well, one good reason is to exclude the property from being included in the JSON representation of the class instance. For example, let's look at a simple class: [crayon-5c6c10207099e236959652/] Now let's look at the JSON representation of a class instance: [crayon-5c6c1020709ac349119614/] This will print [crayon-5c6c1020709ae620268198/] OK, so we do not want our password to be serialized in our JSON. Let's create a decorator to prevent this. Creating the decorator Put the following code into a TypeScript file. [crayon-5c6c1020709af781574730/] Make…