簡體   English   中英

如何為TypeScript的class或interface定義不可序列化的屬性?

[英]How to define a nonserializable property for TypeScript `class` or `interface`?

打字稿

如何為TypeScript classinterface定義不可序列化 (至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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM