I have a didReceiveResponse
callback on a class that extends RESTDataSource in which I return null
if the response status is 404. Because of the typing of RESTDataSource.didReceiveResponse
it appears that this is invalid.
async didReceiveResponse<T>(res: Response, req: Request): Promise<T | null> {
if (res.status === 404) {
return null;
}
return super.didReceiveResponse(res, req);
}
Here is the Typescript error I'm encountering while using --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'.
Is there a way to resolve this typing while still returning null
without disabling the compiler or the strict null check?