Created
February 27, 2020 19:32
-
-
Save omarkdev/45df16aeeaa1085670dc04df830cff53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
@enumerable(true) | |
set name(newName: string) { | |
this._name = newName; | |
} | |
} | |
const user = new User('Marcos'); | |
for (let key in user) { | |
console.log(key); | |
} | |
// error TS1207: Decorators cannot be applied to multiple get/set accessors of the same name. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment