Given this interface from 3rd party library type definitions:
interface IHttpResponse<T> {
data: T;
status: number;
headers: IHttpHeadersGetter;
config: IRequestConfig;
statusText: string;
xhrStatus: 'complete' | 'error' | 'timeout' | 'abort';
}
with IHttpHeadersGetter being this:
interface IHttpHeadersGetter {
(): { [name: string]: string; };
(headerName: string): string;
}
how can I implement headers in a class that implements IHttpResponse<T>?
This is what my class implementation looks like but as one can see, not all members from IHttpHeadersGetter are implemented:
class MockResponse<T> implements IHttpResponse<T> {
data: T;
status: number;
headers (headerName: string): string {
// return some header value
};
config: IRequestConfig;
statusText: string;
xhrStatus: "complete" | "error" | "timeout" | "abort";
}
Thus, tsc complains about this:
error TS2345: Argument of type 'MockResponse<any>' is not assignable to parameter of type 'IHttpResponse<any>'.
Types of property 'headers' are incompatible.
Type '(headerName: string) => string' is not assignable to type 'IHttpHeadersGetter'.
How do I have to implement headers correctly?