Skip to content

[superagent] support generic type for request body#74968

Open
SchroederSteffen wants to merge 6 commits into
DefinitelyTyped:masterfrom
SchroederSteffen:superagent-generic-body
Open

[superagent] support generic type for request body#74968
SchroederSteffen wants to merge 6 commits into
DefinitelyTyped:masterfrom
SchroederSteffen:superagent-generic-body

Conversation

@SchroederSteffen
Copy link
Copy Markdown
Contributor

@SchroederSteffen SchroederSteffen commented May 8, 2026

Please fill in this template.

Select one of these and delete the others:

If changing an existing definition:


We declare DTO classes for our services to describe the request & response bodies.
When testing our services using supertest & superagent, we want to ensure that the request bodies fit the expected type of the endpoint, e.g. as follows:

interface RequestBody { a: boolean; b: number; }
request.post("/").send<RequestBody>({ a: true, b: 42 });

I also thought about adding generics to the request methods (.get(), .post(), etc.) to inherit these types for the .send() method, but I opted for this simpler solution for now.

Comment thread types/superagent/package.json Outdated
"private": true,
"name": "@types/superagent",
"version": "8.1.9999",
"version": "10.0.9999",
Copy link
Copy Markdown
Contributor Author

@SchroederSteffen SchroederSteffen May 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current version of superagent is 10.
From what I can tell, v8 -> v10 only changed Node.js version requirements, so the types shouldn't be affected.
Do we want to align the @types/superagent version as part of this PR or do we want to stay on v8 because the change is compatible?
I tend towards the latter, hence reverting this version change again...

@SchroederSteffen SchroederSteffen marked this pull request as ready for review May 8, 2026 19:24
@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented May 8, 2026

@SchroederSteffen Thank you for submitting this PR!

This is a live comment that I will keep updated.

1 package in this PR

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • 🕐 Most recent commit is approved by a DT maintainer

Once every item on this list is checked, I'll ask you for permission to merge and publish the changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 74968,
  "author": "SchroederSteffen",
  "headCommitOid": "ba23bf2cf97921625a0ae01a8379189e2d95c594",
  "mergeBaseOid": "dafc26dc3da728f912025f73d2629374a9b1aba9",
  "lastPushDate": "2026-05-08T12:51:59.000Z",
  "lastActivityDate": "2026-05-11T19:11:57.000Z",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "tooManyCommits": false,
  "tooManyReviews": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "superagent",
      "kind": "edit",
      "files": [
        {
          "path": "types/superagent/lib/node/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/superagent/superagent-tests.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "NicoZelaya",
        "mxl",
        "shreyjain1994",
        "zopf",
        "beeequeue",
        "lukaselmer",
        "theQuazz",
        "carnesen",
        "ghostganz",
        "LuckyWindsck",
        "DavidTanner"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "lukaselmer",
      "date": "2026-05-09T04:11:12.000Z",
      "isMaintainer": false
    }
  ],
  "mainBotCommentID": 4409234887,
  "ciResult": "pass"
}

@typescript-bot
Copy link
Copy Markdown
Contributor

🔔 @NicoZelaya @mxl @shreyjain1994 @zopf @beeequeue @lukaselmer @theQuazz @carnesen @ghostganz @LuckyWindsck @DavidTanner — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in Pull Request Status Board May 8, 2026
@typescript-bot typescript-bot added the Owner Approved A listed owner of this package signed off on the pull request. label May 9, 2026
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in Pull Request Status Board May 10, 2026
responseType(type: string): this;
retry(count?: number, callback?: CBHandler): this;
send(data?: string | object): this;
send<T extends string | object = string | object>(data?: T): this;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I said this here: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/74967/changes#r3221485120

But this is typically a bad idea, as it doesn't offer any more safety, no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Critical package Owner Approved A listed owner of this package signed off on the pull request.

Projects

Status: Needs Maintainer Review

Development

Successfully merging this pull request may close these issues.

4 participants