![](/img/trans.png)
[英]how to insert a property in typescript class which is not defined in the interface
[英]How to define a nonserializable property for TypeScript `class` or `interface`?
打字稿
如何为TypeScript class
或interface
定义不可序列化 (至JSON)属性? 即我需要这样的东西(JavaScript):
Object.defineProperty(this, 'foo', {
enumerable: false,
configurable: false,
get: function(){return 'stuff';}
});
装饰器的简单示例:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.