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:
e1b45ebd05/lib/request.js (L273)

* Add a couple of extra tests
This commit is contained in:
David Stephens 2020-01-21 21:12:22 +00:00 committed by Ben Lichtman
parent 30446eb4a4
commit 4331db7e1c
2 changed files with 8 additions and 1 deletions

View File

@ -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

View File

@ -7,6 +7,7 @@
// Sami Jaber <https://github.com/samijaber>
// aereal <https://github.com/aereal>
// Jose Luis Leon <https://github.com/JoseLion>
// David Stephens <https://github.com/dwrss>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@ -368,7 +369,7 @@ export interface Request<P extends Params = ParamsDictionary, ResBody = any, Req
* req.is('html');
* // => false
*/
is(type: string): string | false;
is(type: string | string[]): string | false | null;
/**
* Return the protocol string "http" or "https"