Skip to content

Commit f010ffe

Browse files
authored
Merge pull request #107 from malthe/fix-env-cast
Wrap environment keys as record
2 parents 5191634 + 27d8d0b commit f010ffe

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from 'node:tls';
1313
import { EventEmitter } from 'node:events';
1414

15-
import { Defaults, Environment } from './defaults.js';
15+
import { Defaults } from './defaults.js';
1616
import * as logger from './logging.js';
1717

1818
import { postgresqlErrorCodes } from './errors.js';
@@ -147,7 +147,7 @@ interface PreFlightQueue {
147147
bind: Bind | null;
148148
}
149149

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

152152
export type EventMap<
153153
T = {

src/defaults.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { userInfo } from 'node:os';
44
*
55
* See {@link https://www.postgresql.org/docs/current/libpq-envars.html} for a detailed description.
66
*/
7-
export interface Environment {
7+
export type Environment = keyof {
88
PGCLIENTENCODING: string;
99
PGCONNECT_TIMEOUT: string;
1010
PGDATABASE: string;
@@ -23,7 +23,7 @@ function secToMsec(value?: number) {
2323

2424
export class Defaults {
2525
constructor(
26-
env: Environment,
26+
env: Partial<Record<Environment, string>>,
2727
readonly host = env.PGHOST || 'localhost',
2828
readonly port = parseInt(env.PGPORT as string, 10) || 5432,
2929
readonly user = env.PGUSER || userInfo().username,

0 commit comments

Comments
 (0)