diff --git a/types/express-serve-static-core/index.d.ts b/types/express-serve-static-core/index.d.ts index dd012cab4e..e9c136e7ea 100644 --- a/types/express-serve-static-core/index.d.ts +++ b/types/express-serve-static-core/index.d.ts @@ -197,11 +197,11 @@ interface Request extends http.IncomingMessage, Express.Request { * * @param name */ - get(name: string): string; + get(name: string): string | undefined; - header(name: string): string; + header(name: string): string | undefined; - headers: { [key: string]: string; }; + headers: { [key: string]: string | undefined; }; /** * Check if the given `type(s)` is acceptable, returning diff --git a/types/express-serve-static-core/tsconfig.json b/types/express-serve-static-core/tsconfig.json index 40ee779963..cdb77c3573 100644 --- a/types/express-serve-static-core/tsconfig.json +++ b/types/express-serve-static-core/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" diff --git a/types/express/express-tests.ts b/types/express/express-tests.ts index 04165d5e09..cc8c63ef81 100644 --- a/types/express/express-tests.ts +++ b/types/express/express-tests.ts @@ -71,6 +71,15 @@ namespace express_tests { language = req.acceptsLanguages(['en', 'ja']); language = req.acceptsLanguages('en', 'ja'); + let existingHeader1 = req.get('existingHeader') as string; + let nonExistingHeader1 = req.get('nonExistingHeader') as undefined; + + let existingHeader2 = req.header('existingHeader') as string; + let nonExistingHeader2 = req.header('nonExistingHeader') as undefined; + + let existingHeader3 = req.headers.existingHeader as string; + let nonExistingHeader3 = req.headers.nonExistingHeader as undefined; + res.send(req.query['token']); }); diff --git a/types/express/index.d.ts b/types/express/index.d.ts index 9b913db473..d48d58c0c9 100644 --- a/types/express/index.d.ts +++ b/types/express/index.d.ts @@ -2,6 +2,7 @@ // Project: http://expressjs.com // Definitions by: Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 /* =================== USAGE =================== diff --git a/types/express/tsconfig.json b/types/express/tsconfig.json index 0fc87c2800..009cb9ec00 100644 --- a/types/express/tsconfig.json +++ b/types/express/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../"