Member-only story

error TS2339: Property ‘get’ does not exist on type ‘Agent’ (Chai-Http, TypeScript, Mocha)

Tuomas Tonteri
3 min readAug 25, 2024

This TypeScript error was about to get annoying, I wanted to continue writing test cases using Chai-Http as it supposedly should go rather well with the Chai assertion library.

With several other HTTP client libraries, including Node Fetch, also being available and feasible options for use in the tests, it would be good if the Chai-Http usage would be a bit easier to get going smoothly, as it does offer specific support for creating assertions on the HTTP backend behaviour.

However, the test code started to get crowded with all the @ts-expect-error annotations as the Chai-Http introduced functions were not being recognized as part of the types.

The Agent was said not to have the get() function and also the types for the Promise.then() callback function parameters were undetected.

Exception during run: test/chai-http.spec.ts(18,5): error TS2339: Property 'get' does not exist on type 'Agent'.
test/chai-http.spec.ts(19,11): error TS7006: Parameter 'res' implicitly has an 'any' type.

I did have all the necessary packages installed:

  • chai
  • @types/chai
  • chai-http
  • @types/chai-http

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Already have an account? Sign in

Tuomas Tonteri
Tuomas Tonteri

Written by Tuomas Tonteri

0 Followers

Tuomas is a full-stack Senior Software Architect and Cybersecurity Consultant with a keen interest in software assurance, Secure SDLC, and provable security.

No responses yet

Write a response