Merge pull request #28565 from pietu/master

Reorder function overloads to allow typescript compiler to match variant with function as an argument
This commit is contained in:
Mine Starks
2018-09-07 13:41:56 -07:00
committed by GitHub
2 changed files with 13 additions and 1 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
// Type definitions for SuperTest v2.0.1
// Project: https://github.com/visionmedia/supertest
// Definitions by: Alex Varju <https://github.com/varju>
// Petteri Parkkila <https://github.com/pietu>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
@@ -23,12 +24,12 @@ declare namespace supertest {
serverAddress(app: any, path: string): string;
expect(status: number, callback?: CallbackHandler): this;
expect(status: number, body: any, callback?: CallbackHandler): this;
expect(checker: (res: Response) => any): this;
expect(body: string, callback?: CallbackHandler): this;
expect(body: RegExp, callback?: CallbackHandler): this;
expect(body: Object, callback?: CallbackHandler): this;
expect(field: string, val: string, callback?: CallbackHandler): this;
expect(field: string, val: RegExp, callback?: CallbackHandler): this;
expect(checker: (res: Response) => any): this;
end(callback?: CallbackHandler): this;
}
+11
View File
@@ -59,6 +59,17 @@ function hasPreviousAndNextKeys(res: supertest.Response) {
if (!('prev' in res.body)) throw new Error("missing prev key");
}
// functional expect without response type
(request
.get('/') as supertest.Test)
.expect(res => {
if (!('next' in res.body)) return "missing next key";
if (!('prev' in res.body)) throw new Error("missing prev key");
})
.end((err: any, res: supertest.Response) => {
if (err) throw err;
});
// object expect
(request
.get('/') as supertest.Test)