Skip to content

Commit

Permalink
Merge pull request #107 from malthe/fix-env-cast
Browse files Browse the repository at this point in the history
Wrap environment keys as record
  • Loading branch information
malthe authored Feb 28, 2024
2 parents 5191634 + 27d8d0b commit f010ffe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from 'node:tls';
import { EventEmitter } from 'node:events';

import { Defaults, Environment } from './defaults.js';
import { Defaults } from './defaults.js';
import * as logger from './logging.js';

import { postgresqlErrorCodes } from './errors.js';
Expand Down Expand Up @@ -147,7 +147,7 @@ interface PreFlightQueue {
bind: Bind | null;
}

const DEFAULTS = new Defaults(env as unknown as Environment);
const DEFAULTS = new Defaults(env as Record<string, string>);

export type EventMap<
T = {
Expand Down
4 changes: 2 additions & 2 deletions src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { userInfo } from 'node:os';
*
* See {@link https://www.postgresql.org/docs/current/libpq-envars.html} for a detailed description.
*/
export interface Environment {
export type Environment = keyof {
PGCLIENTENCODING: string;
PGCONNECT_TIMEOUT: string;
PGDATABASE: string;
Expand All @@ -23,7 +23,7 @@ function secToMsec(value?: number) {

export class Defaults {
constructor(
env: Environment,
env: Partial<Record<Environment, string>>,
readonly host = env.PGHOST || 'localhost',
readonly port = parseInt(env.PGPORT as string, 10) || 5432,
readonly user = env.PGUSER || userInfo().username,
Expand Down

0 comments on commit f010ffe

Please sign in to comment.