I'm having trouble getting my custom @enumerable
decorator to work properly. I followed the example in the documentation, but it's not functioning as expected. Am I overlooking something?
Decorator
export function enumerable(value: boolean) {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
descriptor.enumerable = value;
};
}
Class
export class MyClass {
@enumerable(true)
get getter():string {
return 'value';
}
}
Test
var cls = new MyClass();
console.log(cls.propertyIsEnumerable('getter')); // returns false, expected true
console.log(Object.keys(cls)); // returns [], expected ["getter"]
console.log(JSON.stringify(cls)); // returns {}, expected {"getter":"value"}
tsconfig.json
{
"compilerOptions": {
// "target": "ES2015",
"target": "ES5",
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false
}
}