2017-10-10 69 views
0

打字稿如何定義TypeScript`class`或`interface`的非序列化屬性?

如何定義非序列(以JSON)財產打字稿classinterface?即我需要的是這樣的(JavaScript的):

Object.defineProperty(this, 'foo', { 
    enumerable: false, 
    configurable: false, 
    get: function(){return 'stuff';} 
}); 
+0

非序列化到JSON –

+0

@Rajesh這將是'枚舉:真, 可配置:真' –

+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

相關問題