From 806d287affd7a0712f776e06470a55233d560516 Mon Sep 17 00:00:00 2001 From: Vitaly Tomilov Date: Thu, 29 Aug 2019 01:26:48 +0100 Subject: [PATCH] improving type precision --- src/main.ts | 14 ++++++-------- test/main.spec.ts | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main.ts b/src/main.ts index 2abf496..a4ce9b8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,7 @@ import {HostType, IConnectionDefaults, IEncodingOptions, IHost, IParsedHost} from './types'; import {decode, encode, fullHostName, isText} from './utils'; -const invalidDefaults = 'Invalid "defaults" parameter: '; +const errInvalidDefaults = 'Invalid "defaults" parameter: '; export class ConnectionString { @@ -10,19 +10,17 @@ export class ConnectionString { user?: string; password?: string; path?: string[]; - params?: { [name: string]: any }; + params?: { [name: string]: string }; /** - * Virtualized accessor to the first host name: - * = hosts && hosts[0].name + * Virtualized accessor to the first host name. */ get hostname(): string | undefined { return this.hosts && this.hosts[0].name; } /** - * Virtualized accessor to the first host's port: - * = hosts && hosts[0].port + * Virtualized accessor to the first host's port. */ get port(): number | undefined { return this.hosts && this.hosts[0].port; @@ -39,7 +37,7 @@ export class ConnectionString { } if (defaults !== undefined && defaults !== null && typeof defaults !== 'object') { - throw new TypeError(invalidDefaults + JSON.stringify(defaults)); + throw new TypeError(errInvalidDefaults + JSON.stringify(defaults)); } cs = cs.trim(); @@ -240,7 +238,7 @@ export class ConnectionString { setDefaults(defaults: IConnectionDefaults): this { if (!defaults || typeof defaults !== 'object') { - throw new TypeError(invalidDefaults + JSON.stringify(defaults)); + throw new TypeError(errInvalidDefaults + JSON.stringify(defaults)); } if (!('protocol' in this) && isText(defaults.protocol)) { diff --git a/test/main.spec.ts b/test/main.spec.ts index 982585d..ad401c5 100644 --- a/test/main.spec.ts +++ b/test/main.spec.ts @@ -423,7 +423,7 @@ describe('toString', () => { }; const a = parse('', {params: {value1: obj, value2: 'text'}}); const b = parse(a.toString()); - expect(JSON.parse(b.params && b.params.value1)).to.eql(obj); + expect(JSON.parse((b.params && b.params.value1))).to.eql(obj); }); it('must ignore empty parameter list', () => { const a = parse('');