How to create a type excluding instance methods from a class in typescript?

后端 未结 3 1424
小蘑菇
小蘑菇 2021-02-05 17:19

Given a class, containing both properties and methods, I\'d like to derive a type that just contains its properties.

For example, if I define a class as follow:

         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 18:10

    While reading this issue, I found someone posting this succinct type

    type ExcludeMethods = 
      Pick any ? never : K }[keyof T]>;
    

    Note that this type does not remove getters and setters.

提交回复
热议问题