From 4331db7e1c7da5e87bf2faa41e2c81859e125ab8 Mon Sep 17 00:00:00 2001 From: David Stephens Date: Tue, 21 Jan 2020 21:12:22 +0000 Subject: [PATCH] express-serve-static-core-tests: Update `req.is` to match the actual function in express (#41636) * Update `req.is` to match the actual function. The parameters can be a string or an array and return type can be null. This is described in the JSDoc for the function: https://github.com/expressjs/express/blob/e1b45ebd050b6f06aa38cda5aaf0c21708b0c71e/lib/request.js#L273 * Add a couple of extra tests --- .../express-serve-static-core-tests.ts | 6 ++++++ types/express-serve-static-core/index.d.ts | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/types/express-serve-static-core/express-serve-static-core-tests.ts b/types/express-serve-static-core/express-serve-static-core-tests.ts index 4e9f75a5ad..ccd70e7a1f 100644 --- a/types/express-serve-static-core/express-serve-static-core-tests.ts +++ b/types/express-serve-static-core/express-serve-static-core-tests.ts @@ -9,6 +9,12 @@ app.listen(3000, (err: any) => { app.get('/:foo', req => { req.params.foo; // $ExpectType string req.params[0]; // $ExpectType string + // $ExpectType string | false | null + req.is(['application/json', 'application/xml']); + // $ExpectType string | false | null + req.is('audio/wav'); + // $ExpectError + req.is(1); }); // Params can used as an array diff --git a/types/express-serve-static-core/index.d.ts b/types/express-serve-static-core/index.d.ts index 519dbbbb87..9095a3bec2 100644 --- a/types/express-serve-static-core/index.d.ts +++ b/types/express-serve-static-core/index.d.ts @@ -7,6 +7,7 @@ // Sami Jaber // aereal // Jose Luis Leon +// David Stephens // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -368,7 +369,7 @@ export interface Request

false */ - is(type: string): string | false; + is(type: string | string[]): string | false | null; /** * Return the protocol string "http" or "https"