From 0249359fe12157f849f59475d3f2a66cfcb01b0e Mon Sep 17 00:00:00 2001 From: Michael Zugelder Date: Thu, 18 May 2017 14:36:55 +0200 Subject: [PATCH] basic-auth: Make auth return value optional --- types/basic-auth/basic-auth-tests.ts | 7 +++++-- types/basic-auth/index.d.ts | 3 ++- types/basic-auth/tsconfig.json | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/types/basic-auth/basic-auth-tests.ts b/types/basic-auth/basic-auth-tests.ts index 1fab9c10e2..84f99d9f2f 100644 --- a/types/basic-auth/basic-auth-tests.ts +++ b/types/basic-auth/basic-auth-tests.ts @@ -1,4 +1,7 @@ - +import {IncomingMessage} from 'http'; import auth = require('basic-auth'); -auth(null); +const loginData = auth(undefined! as IncomingMessage); +if (loginData) { + const {name, pass} = loginData; +} diff --git a/types/basic-auth/index.d.ts b/types/basic-auth/index.d.ts index 51ada3b0c7..37a8495f83 100644 --- a/types/basic-auth/index.d.ts +++ b/types/basic-auth/index.d.ts @@ -7,7 +7,8 @@ import * as http from 'http'; -declare function auth(req: http.IncomingMessage): auth.BasicAuthResult; +// See https://github.com/jshttp/basic-auth/blob/v1.1.0/index.js#L49 +declare function auth(req: http.IncomingMessage): auth.BasicAuthResult | undefined; declare namespace auth { interface BasicAuthResult { diff --git a/types/basic-auth/tsconfig.json b/types/basic-auth/tsconfig.json index b9f77df9d2..8d9222de2c 100644 --- a/types/basic-auth/tsconfig.json +++ b/types/basic-auth/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../"