Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#59917 [cookie-parser] Add secret to expres…
Browse files Browse the repository at this point in the history
…s's request by @mckramer
  • Loading branch information
mckramer authored Apr 27, 2022
1 parent 9281c8a commit 44512fd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions types/cookie-parser/cookie-parser-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import cookieParser = require('cookie-parser');
const app = express();
app.use(cookieParser('optional secret string'));

const req = null as any as express.Request;
req.secret; // $ExpectType string | undefined

let obj: object;
let str: string;
let notTrue: false;
Expand Down
14 changes: 14 additions & 0 deletions types/cookie-parser/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@

import * as express from 'express';

declare global {
namespace Express {
// Inject additional properties on express.Request
interface Request {
/**
* This request's secret.
* Optionally set by cookie-parser if secret(s) are provided. Can be used by other middleware.
* [Declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html) can be used to add your own properties.
*/
secret?: string;
}
}
}

declare function cookieParser(secret?: string | string[], options?: cookieParser.CookieParseOptions): express.RequestHandler;

declare namespace cookieParser {
Expand Down

0 comments on commit 44512fd

Please sign in to comment.