Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeScript] response.headers.hasContentType() raises 2 illegitimate TS errors #6250

Open
OlivierZal opened this issue Feb 21, 2024 · 0 comments

Comments

@OlivierZal
Copy link

OlivierZal commented Feb 21, 2024

Describe the bug

response.headers.hasContentType() (where response: axios.AxiosResponse<any, any>) raises 2 illegitimate TS errors although this expression works as expected:

Cannot invoke an object which is possibly 'null' or 'undefined'. ts(2723)
This expression is not callable. ts(2349)
  Not all constituents of type 'string | number | boolean | AxiosHeaders | string[] | ((matcher?: AxiosHeaderMatcher | undefined) => boolean)' are callable.
    Type 'string' has no call signatures.

To Reproduce

e.g. https://codesandbox.io/p/devbox/lucid-dawn-82cn7d

  • Run tsc in a Terminal to raise the TS errors.
  • Run node src/index.js to confirm that the code works.

Code snippet

import axios from "axios";
const response = await axios.post("http://httpbin.org/post", { x: 1 });

console.log(response.headers.hasContentType("application/json"));
console.log(response.headers.hasContentType("application/xml"));

Expected behavior

response.headers.hasContentType() (where response: axios.AxiosResponse<any, any>) shouldn't raise any TS error and be recognized as a boolean by TypeScript.

Axios Version

1.6.7

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

21.6.2

OS

No response

Additional Library Versions

TypeScript 5.3.3

Additional context/Screenshots

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant