我尝试了很多方法来用玩笑来模拟一个通用函数,但都没有成功。这是我认为正确的方式:
interface ServiceInterface {
get<T>(): T;
}
class Service implements ServiceInterface {
get = jest.fn(<T>(): T => {
throw new Error("Method not implemented.");
});
}
在编译时它会抛出以下错误:
error TS2416: Property 'get' in type 'Service' is not assignable to the same property in base type 'ServiceInterface'.
Type 'Mock<{}, any[]>' is not assignable to type '<T>() => T'.
Type '{}' is not assignable to type 'T'.
你能告诉我正确的方法吗?
谢谢