diff --git a/types/basic-auth/basic-auth-tests.ts b/types/basic-auth/basic-auth-tests.ts index 22e27a5a49..e416afe352 100644 --- a/types/basic-auth/basic-auth-tests.ts +++ b/types/basic-auth/basic-auth-tests.ts @@ -1,6 +1,12 @@ - +import {IncomingMessage} from 'http'; import auth = require('basic-auth'); -auth(null); +const loginData = auth(undefined! as IncomingMessage); +if (loginData) { + const {name, pass} = loginData; +} -auth.parse('Basic QmFzaWM6QXV0aA=='); +const parsed = auth.parse('Basic QmFzaWM6QXV0aA=='); +if (parsed) { + const {name, pass} = parsed; +} diff --git a/types/basic-auth/index.d.ts b/types/basic-auth/index.d.ts index 8292f1349f..276b5b8af6 100644 --- a/types/basic-auth/index.d.ts +++ b/types/basic-auth/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for basic-auth v1.1.0 +// Type definitions for basic-auth 1.1 // Project: https://github.com/jshttp/basic-auth // Definitions by: Clément Bourgeois , Vesa Poikajärvi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -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": [ "../" diff --git a/types/basic-auth/tslint.json b/types/basic-auth/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/basic-auth/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file