From 5493ac61cd9f2727acc0954634f843d6c1b33948 Mon Sep 17 00:00:00 2001 From: Steffen Schroeder Date: Tue, 14 Jul 2026 09:24:48 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#74967=20[super?= =?UTF-8?q?test]=20support=20generic=20type=20for=20expected=20response=20?= =?UTF-8?q?body=20by=20@SchroederSteffen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/supertest/lib/test.d.ts | 4 ++-- types/supertest/supertest-tests.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/types/supertest/lib/test.d.ts b/types/supertest/lib/test.d.ts index 123cd27568f1fd..aa5c963ec0d48f 100644 --- a/types/supertest/lib/test.d.ts +++ b/types/supertest/lib/test.d.ts @@ -9,11 +9,11 @@ declare class Test extends Request { serverAddress(app: App, path: string): string; expect(status: number, callback?: CallbackHandler): this; - expect(status: number, body: any, callback?: CallbackHandler): this; + expect(status: number, body: T, callback?: CallbackHandler): this; expect(checker: (res: Response) => any, callback?: CallbackHandler): this; expect(body: string, callback?: CallbackHandler): this; expect(body: RegExp, callback?: CallbackHandler): this; - expect(body: object, callback?: CallbackHandler): this; + expect(body: T, callback?: CallbackHandler): this; expect(field: string, val: string, callback?: CallbackHandler): this; expect(field: string, val: RegExp, callback?: CallbackHandler): this; end(callback?: CallbackHandler): this; diff --git a/types/supertest/supertest-tests.ts b/types/supertest/supertest-tests.ts index a1a368f8507a80..ca242da0b8b55a 100644 --- a/types/supertest/supertest-tests.ts +++ b/types/supertest/supertest-tests.ts @@ -100,3 +100,14 @@ request.get("/") .end((err: any, res: supertest.Response) => { if (err) throw err; }); + +// generic expect +interface ResponseBody { + a: boolean; + b: number; +} +request.get("/") + .expect({ a: true, b: 42 }) + .expect({ a: true, b: 42 }) + .expect(200, { a: true, b: 42 }) + .expect(200, { a: true, b: 42 }); From 69fed838864acc038a1cff479b8f9006de52a438 Mon Sep 17 00:00:00 2001 From: Steffen Schroeder Date: Tue, 14 Jul 2026 09:27:07 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#74968=20[super?= =?UTF-8?q?agent]=20support=20generic=20type=20for=20request=20body=20by?= =?UTF-8?q?=20@SchroederSteffen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/superagent/lib/node/index.d.ts | 14 +++++++------- types/superagent/superagent-tests.ts | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/types/superagent/lib/node/index.d.ts b/types/superagent/lib/node/index.d.ts index ee79d9274f92ec..84ef63044ad8bc 100644 --- a/types/superagent/lib/node/index.d.ts +++ b/types/superagent/lib/node/index.d.ts @@ -1,18 +1,18 @@ +import { Blob } from "buffer"; +import { AppendOptions } from "form-data"; +import { ReadStream } from "fs"; import * as http from "http"; import * as http2 from "http2"; import * as https from "https"; +import { LookupFunction } from "net"; import { Stream } from "stream"; +import { AgentOptions as SAgentOptions, CBHandler, URLType } from "../../types"; +import { Request as Http2Request } from "./http2wrapper"; import methods = require("methods"); import SAgent = require("./agent"); -import { Blob } from "buffer"; -import { ReadStream } from "fs"; -import { LookupFunction } from "net"; import RequestBase = require("../request-base"); import ResponseBase = require("./response"); -import { AppendOptions } from "form-data"; -import { AgentOptions as SAgentOptions, CBHandler, URLType } from "../../types"; -import { Request as Http2Request } from "./http2wrapper"; type GlobalBlob = typeof globalThis extends { Blob: infer T } ? T extends abstract new(...args: any) => infer I ? I : never @@ -91,7 +91,7 @@ declare class SARequest extends Stream implements RequestBase { redirects(n: number): this; responseType(type: string): this; retry(count?: number, callback?: CBHandler): this; - send(data?: string | object): this; + send(data?: T): this; serialize(serializer: (obj: any) => string): this; set(field: "Cookie", val: string[]): this; set(field: http.IncomingHttpHeaders): this; diff --git a/types/superagent/superagent-tests.ts b/types/superagent/superagent-tests.ts index c0c8f901eb33a8..e748a345e54d37 100644 --- a/types/superagent/superagent-tests.ts +++ b/types/superagent/superagent-tests.ts @@ -1,9 +1,9 @@ // via: http://visionmedia.github.io/superagent/ import request = require("superagent"); -import * as fs from "fs"; -import assert = require("assert"); import { Blob } from "buffer"; +import * as fs from "fs"; import { Agent } from "https"; +import assert = require("assert"); // Examples taken from https://github.com/visionmedia/superagent/blob/gh-pages/docs/index.md // and https://github.com/visionmedia/superagent/blob/master/Readme.md @@ -375,3 +375,13 @@ request("POST", "/").http2().end(callback); agent.get("/").http2().end(callback); void testDefaultOptions(); + +// generic body +interface RequestBody { + a: boolean; + b: number; +} +request.post("/").send("generic"); +request.post("/").send("generic"); +request.post("/").send({ a: true, b: 42 }); +request.post("/").send({ a: true, b: 42 });