{"id":17353,"library":"retyped-chai-http-tsd-ambient","title":"Retyped Chai-HTTP Typings","description":"This package provides TypeScript ambient type declarations for the `chai-http` library. It originates from the `retyped` project, which aimed to offer curated typings for various JavaScript libraries. However, the `retyped` project itself appears to be abandoned, with most packages, including this one, maintaining a `0.0.0-0` version number, indicating no active development or updates. Modern `chai-http` (version 4.2.4 and above) ships with its own built-in TypeScript definitions, making external typing packages like `retyped-chai-http-tsd-ambient` largely obsolete. Users are generally advised to rely on `chai-http`'s native types rather than this unmaintained package or even the stub `@types/chai-http` package.","status":"abandoned","version":"0.0.0-0","language":"javascript","source_language":"en","source_url":"https://github.com/retyped/chai-http-tsd-ambient","tags":["javascript","retyped","tsd","tsd-ambient"],"install":[{"cmd":"npm install retyped-chai-http-tsd-ambient","lang":"bash","label":"npm"},{"cmd":"yarn add retyped-chai-http-tsd-ambient","lang":"bash","label":"yarn"},{"cmd":"pnpm add retyped-chai-http-tsd-ambient","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package provides type definitions for the `chai-http` runtime library. It is a devDependency.","package":"chai-http","optional":false},{"reason":"`chai-http` is a plugin for the `chai` assertion library, so `chai` is implicitly required for runtime usage and its types.","package":"chai","optional":false},{"reason":"Chai-HTTP extends `superagent`'s request interface. Missing `@types/superagent` can lead to TypeScript errors regarding HTTP method properties (e.g., `.get()`, `.post()`) on the `Agent` type.","package":"@types/superagent","optional":true}],"imports":[{"note":"Standard ES module import for the Chai assertion library. `chai-http` augments the `chai` namespace.","wrong":"const chai = require('chai');","symbol":"chai","correct":"import * as chai from 'chai';"},{"note":"Chai-HTTP is typically imported as a default export. For CommonJS environments with TypeScript, `import chaiHttp = require('chai-http');` is a specific syntax to ensure type augmentation works correctly, especially with older `chai-http` types. However, with `chai-http`'s built-in types, the `import` statement usually suffices.","wrong":"import { chaiHttp } from 'chai-http'; // Incorrect named import\nconst chaiHttp = require('chai-http'); // Might lose type augmentation without specific TS syntax","symbol":"chaiHttp","correct":"import chaiHttp from 'chai-http';"},{"note":"While `chaiHttp` is often used to enable the plugin, `request` can also be directly imported from `chai-http` for making requests, especially when not using `chai.use()` with an `app`.","wrong":"import * as request from 'chai-http'; // Incorrect if only `request` is needed","symbol":"request","correct":"import { request } from 'chai-http';"}],"quickstart":{"code":"import * as chai from 'chai';\nimport chaiHttp from 'chai-http';\nimport { Application } from 'express'; // Assuming Express.js application\nimport 'mocha'; // For test runner globals\n\n// Optionally import superagent types if not implicitly resolved by chai-http's built-in types\n// import '@types/superagent';\n\n// Initialize Chai HTTP plugin\nchai.use(chaiHttp);\n\n// Create a dummy Express app for testing\nconst app: Application = require('express')();\napp.get('/test', (req, res) => res.status(200).send('Hello Test!'));\napp.post('/data', (req, res) => res.status(201).json({ message: 'Data received' }));\n\ndescribe('Chai-HTTP with TypeScript', () => {\n  it('should get a successful response from /test', (done) => {\n    chai.request(app)\n      .get('/test')\n      .end((err, res) => {\n        chai.expect(err).to.be.null;\n        chai.expect(res).to.have.status(200);\n        chai.expect(res.text).to.equal('Hello Test!');\n        done();\n      });\n  });\n\n  it('should post data and get a created response from /data', (done) => {\n    chai.request(app)\n      .post('/data')\n      .send({ item: 'test' })\n      .end((err, res) => {\n        chai.expect(err).to.be.null;\n        chai.expect(res).to.have.status(201);\n        chai.expect(res).to.be.json;\n        chai.expect(res.body.message).to.equal('Data received');\n        done();\n      });\n  });\n});\n","lang":"typescript","description":"Demonstrates a basic TypeScript test setup using `chai`, `chai-http`, and `mocha` to make and assert HTTP requests against a simple Express.js application, leveraging the provided typings."},"warnings":[{"fix":"Migrate to `chai-http`'s built-in type definitions, as `chai-http` (v4.2.4+) now ships with its own types. Remove `retyped-chai-http-tsd-ambient` and `@types/chai-http` (which is a stub).","message":"The `retyped` project, which this package is part of, appears to be abandoned (last activity on GitHub for the main repo was in 2017). This package is unlikely to receive updates for new `chai-http` versions or TypeScript changes.","severity":"breaking","affected_versions":">=0.0.0-0"},{"fix":"Uninstall `retyped-chai-http-tsd-ambient` and `@types/chai-http`. Ensure `chai-http` is updated to a version that includes its own types (e.g., `npm install chai-http@latest`).","message":"`chai-http` (versions 4.2.4 and newer) provides its own type declarations directly within the package. Installing `retyped-chai-http-tsd-ambient` or `@types/chai-http` is unnecessary and can potentially lead to type conflicts or outdated definitions.","severity":"gotcha","affected_versions":">=0.0.0-0"},{"fix":"Use ES module imports: `import chaiHttp from 'chai-http';` or, for explicit CommonJS type augmentation in older setups, `import chaiHttp = require('chai-http');`.","message":"When using `chai-http` with TypeScript, particularly in CommonJS environments, incorrect import syntax can prevent type augmentation of `chai`. For example, `const chaiHttp = require('chai-http')` might not correctly apply types.","severity":"gotcha","affected_versions":">=0.0.0-0"},{"fix":"Install `@types/superagent` as a devDependency: `npm install --save-dev @types/superagent`. This typically resolves issues with missing HTTP method types on `chai.request` objects.","message":"TypeScript errors such as 'Property 'get' does not exist on type 'Agent'' can occur if the types for `superagent` (which `chai-http` uses internally) are not correctly resolved or are missing. This is because `chai-http` extends `superagent`'s request objects.","severity":"gotcha","affected_versions":">=0.0.0-0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure `chai-http` is installed and updated to a version with built-in types. Remove `retyped-chai-http-tsd-ambient` and `@types/chai-http`. If using an older `chai-http` version, ensure `import chaiHttp = require('chai-http');` is used in CommonJS contexts.","cause":"The TypeScript compiler cannot find the `request` property augmentation on the `chai` object, typically due to missing or incorrectly loaded `chai-http` type declarations.","error":"Property 'request' does not exist on type 'ChaiStatic'."},{"fix":"Install `@types/superagent` as a development dependency: `npm install --save-dev @types/superagent`. This provides the necessary declarations for the HTTP methods.","cause":"The types for `superagent`, which `chai-http` extends, are not correctly applied, leading to missing HTTP method declarations on the `chai.request` object.","error":"Property 'get' does not exist on type 'Agent'."},{"fix":"Ensure `chai-http` is installed and that its version includes built-in types. If not, consider upgrading `chai-http` or manually installing `@types/chai-http` (though `chai-http`'s native types are preferred if available). Confirm your `tsconfig.json` includes `node_modules/@types` in `typeRoots` or similar.","cause":"TypeScript cannot locate the type definition files (`.d.ts`) for `chai-http`.","error":"Could not find a declaration file for module 'chai-http'."},{"fix":"Ensure all relevant typing packages (`chai`, `chai-http`, `superagent`) are installed and properly configured. Explicitly type the callback parameters (e.g., `(err: any, res: ChaiHttp.Response) => { ... }`) as a temporary workaround, but the root cause is usually missing or conflicting types.","cause":"When using `chai-http` with Promises or callbacks, TypeScript might not infer the type of the `res` (response) object if `chai-http`'s types or `superagent`'s types are not fully resolved, or if `chai.use(chaiHttp)` is not correctly applied.","error":"Parameter 'res' implicitly has an 'any' type."}],"ecosystem":"npm","meta_description":null}