Skip to content

Commit

Permalink
improving type precision
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Aug 29, 2019
1 parent 74c2935 commit 806d287
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion test/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(<string>(b.params && b.params.value1))).to.eql(obj);
});
it('must ignore empty parameter list', () => {
const a = parse('');
Expand Down

0 comments on commit 806d287

Please sign in to comment.