![](/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.