How to access non static property from static function in typescript

前端 未结 2 373
有刺的猬
有刺的猬 2021-01-18 18:39

I am mocking the User and need to implement static method findOne which is static so I do not need to extensiate User in my calling cl

2条回答
  •  暖寄归人
    2021-01-18 18:56

    try this

    export class test
    {
     private static t:test;
     private name:string;
     constructor()
     {
       t=this;
     }
    
    public static sample()
    {
       return t.name;
    }
    }
    

提交回复
热议问题