[supertest] support generic type for expected response body#74967
[supertest] support generic type for expected response body#74967SchroederSteffen wants to merge 4 commits into
Conversation
|
@SchroederSteffen Thank you for submitting this PR! This is a live comment that I will keep updated. 1 package in this PRCode ReviewsBecause 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
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": 74967,
"author": "SchroederSteffen",
"headCommitOid": "1cff41d520d1ecae6246fbf8f829a00c5dad02e3",
"mergeBaseOid": "dafc26dc3da728f912025f73d2629374a9b1aba9",
"lastPushDate": "2026-05-08T12:49:38.000Z",
"lastActivityDate": "2026-05-12T05:22:55.000Z",
"hasMergeConflict": false,
"isFirstContribution": false,
"tooManyFiles": false,
"hugeChange": false,
"tooManyCommits": false,
"tooManyReviews": false,
"popularityLevel": "Critical",
"pkgInfo": [
{
"name": "supertest",
"kind": "edit",
"files": [
{
"path": "types/supertest/lib/test.d.ts",
"kind": "definition"
},
{
"path": "types/supertest/supertest-tests.ts",
"kind": "test"
}
],
"owners": [
"varju",
"pietu",
"DavidTanner"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Critical"
}
],
"reviews": [
{
"type": "changereq",
"reviewer": "lukaselmer",
"date": "2026-05-12T02:59:50.000Z"
}
],
"mainBotCommentID": 4409232256,
"ciResult": "pass"
} |
|
🔔 @varju @pietu @DavidTanner — please review this PR in the next few days. Be sure to explicitly select |
|
|
||
| expect(status: number, callback?: CallbackHandler): this; | ||
| expect(status: number, body: any, callback?: CallbackHandler): this; | ||
| expect<T extends any = any>(status: number, body: T, callback?: CallbackHandler): this; |
There was a problem hiding this comment.
This is typically a bad idea; this is tantamount to allowing any because anything can infer into it anyway. Adding the type param doesn't really add much more safety, no?
(We are supposed to have a lint rule that complains about this)
There was a problem hiding this comment.
Agree.
expect<T>(...) is enough. extends any = any can be removed
lukaselmer
left a comment
There was a problem hiding this comment.
Let's remove extends any = any
|
@SchroederSteffen One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits. Thank you! |
|
That doesn't change the fact that the type param is only used once |
Please fill in this template.
pnpm test <package to test>.Select one of these and delete the others:
If changing an existing definition:
package.json.We declare DTO classes for our services to describe the request & response bodies.
When testing our services using
supertest, we want to ensure that the expected bodies fit the return type of the endpoint, e.g. as follows:I also thought about adding generics to the request methods (
.get(),.post(), etc.) to inherit these types for the.expect()methods, but I opted for this simpler solution for now.Fixes forwardemail/supertest#720.
Fixes forwardemail/superagent#1834.
Related: