mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
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:
parent
30446eb4a4
commit
4331db7e1c
@ -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
|
||||
|
||||
3
types/express-serve-static-core/index.d.ts
vendored
3
types/express-serve-static-core/index.d.ts
vendored
@ -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"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user