我有一个didReceiveResponse
扩展 RESTDataSource 的类的回调,null
如果响应状态为 404,我将在其中返回。由于它的输入,RESTDataSource.didReceiveResponse
这似乎是无效的。
async didReceiveResponse<T>(res: Response, req: Request): Promise<T | null> {
if (res.status === 404) {
return null;
}
return super.didReceiveResponse(res, req);
}
这是我在使用时遇到的 Typescript 错误--strict-null-checks
TS2416: Property 'didReceiveResponse' in type 'APIDataSource' is not assignable to the same property in base type 'RESTDataSource<ResolverContext>'.
Type '<T>(res: Response, req: Request) => Promise<T | null>' is not assignable to type '<TResult = any>(response: Response, _request: Request) => Promise<TResult>'.
Type 'Promise<TResult | null>' is not assignable to type 'Promise<TResult>'.
Type 'TResult | null' is not assignable to type 'TResult'.
Type 'null' is not assignable to type 'TResult'.
null
有没有办法在不禁用编译器或严格的空检查的情况下在返回的同时解决这种打字问题?