我想使用 redis 客户端promisify
:
import type { RedisClient } from "redis";
import * as util from "util";
class MyClass {
private redisClient: RedisClient;
constructor(client: RedisClient) {
this.redisClient = client;
}
getMyData = (): SomeType[] => {
const getAsync: Promise<string | undefined> = util.promisify(this.redisClient.get).bind(this.redisClient);
// ...
};
}
但是我遇到了 eslint 的两个问题:
ESLint: Avoid referencing unbound methods which may cause unintentional scoping of 'this'.(@typescript-eslint/unbound-method)
在this.redisClient.get
片段
和
ESLint: Unsafe assignment of an any value.(@typescript-eslint/no-unsafe-assignment)
在getAsync
我如何promisify
以一种可以识别类型和适当this
范围的方式使用?