繁体   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