Access to static properties via this.constructor in typescript

前端 未结 6 2277
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-18 13:49

I want to write es6 class:

class SomeClass {
    static prop = 123

    method() {
    }
}

How to get access to static prop from <

6条回答
  •  被撕碎了的回忆
    2021-02-18 14:44

    I guess that you want in the future extends this class. So it is better to do this:

    class SomeClass {
        static prop = 123
    
        method() {
            (this.constructor as T).prop;
        }
    }
    

提交回复
热议问题