From 84ad0786dbdadb0eea36bd7377302e0db354ade3 Mon Sep 17 00:00:00 2001 From: Mayur Borse Date: Sat, 1 May 2021 17:46:23 +0530 Subject: [PATCH] using 'in' as type guard --- lib/connectors/postgres-connector.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/connectors/postgres-connector.ts b/lib/connectors/postgres-connector.ts index 481f337..dc992c1 100644 --- a/lib/connectors/postgres-connector.ts +++ b/lib/connectors/postgres-connector.ts @@ -5,27 +5,21 @@ import type { SupportedSQLDatabaseDialect } from "../translators/sql-translator. import type { QueryDescription } from "../query-builder.ts"; import type { Values } from "../data-types.ts"; -interface PostgresOptionsBase extends ConnectorOptions { +interface PostgresOptionsWithConfig extends ConnectorOptions { database: string; host: string; username: string; password: string; port?: number; - // unused types - uri?: never; } interface PostgresOptionsWithURI extends ConnectorOptions { uri: string; - // unused types - database?: never; - host?: never; - username?: never; - password?: never; - port?: never; } -export type PostgresOptions = PostgresOptionsWithURI | PostgresOptionsBase; +export type PostgresOptions = + | PostgresOptionsWithConfig + | PostgresOptionsWithURI; export class PostgresConnector implements Connector { _dialect: SupportedSQLDatabaseDialect = "postgres"; @@ -38,7 +32,7 @@ export class PostgresConnector implements Connector { /** Create a PostgreSQL connection. */ constructor(options: PostgresOptions) { this._options = options; - if (options.hasOwnProperty("uri")) { + if ("uri" in options) { this._client = new PostgresClient(options.uri); } else { this._client = new PostgresClient({