打字稿
如何为TypeScript class
或interface
定义不可序列化的(到JSON)属性?即我需要这样的东西(JavaScript):
Object.defineProperty(this, 'foo', {
enumerable: false,
configurable: false,
get: function(){return 'stuff';}
});
答案 0 :(得分:0)
装饰器的快速示例:
function configureProperty(enumerable: boolean, configurable: boolean) {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
descriptor.enumerable = enumerable;
descriptor.configurable = configurable;
};
}
class Foo {
name = 'test';
@configureProperty(false, false)
get bar() { return 'stuff'; }
}
**您需要启用experimentalDecorators