I am currently working on a rest call that may return a header that I need to store. In order to do this, I have to first check if the header is present before storing it.
Here is how I approached it:
private getHeader(response: AxiosResponse) {
if (response.headers.has('myheader')) {
storeHeader(response.headers['myheader']);
}
}
However, when trying to execute response.headers.has
, TypeScript gives me the following errors:
TS18049: 'response.headers.has' is possibly 'null' or 'undefined'.
TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
TS2349: This expression is not callable. Not all constituents of type 'string | number | boolean | AxiosHeaders | string[] | ((header: string, matcher?: true | AxiosHeaderMatcher | undefined) => boolean)' are callable. Type 'string' has no call signatures.