Skip to content

Instantly share code, notes, and snippets.

function enumerable(newValue: boolean) {
return (
target: any,
propertyKey: string,
propertyDescriptor: PropertyDescriptor,
) => {
propertyDescriptor.enumerable = newValue;
}
}
class User {
_name: string;
constructor(name: string) {
this._name = name;
}
@enumerable(true)
get name() {
return this._name;
}
}
const user = new User('Marcos');
for (let key in user) {
console.log(key);
}
// _name
// name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment