在打字稿中访问类中属性的装饰器值

时间:2021-07-27 20:50:04

标签: typescript reflect-metadata

class TestClass{ 
  @Expose({name:"public_id"})
  publicId!:string
}

我正在使用 class-transformer 库来序列化打字稿中的数据。在上面的例子中,我想访问“Expose”装饰器上“name”的值。

简单地说,我希望能够做到这一点。

const test = new TestClass();
getExposeValueOf(test.publicId);//should print "public_id"

0 个答案:

没有答案