Skip to content

Commit 3b23b60

Browse files
authored
🤖 Merge PR DefinitelyTyped#72710 fix(pg): named exports by @perrin4869
1 parent fac1aa7 commit 3b23b60

File tree

4 files changed

+61
-20
lines changed

4 files changed

+61
-20
lines changed

types/pg/index.d.mts

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
1-
import type * as pg from "./index.d.ts";
2-
3-
import TypeOverrides = require("./lib/type-overrides");
4-
5-
export type * from "./index.d.ts";
6-
7-
export const defaults: typeof pg.defaults;
8-
export const Client: typeof pg.Client;
9-
export const Query: typeof pg.Query;
10-
export const Pool: typeof pg.Pool;
11-
export const Connection: typeof pg.Connection;
12-
export const types: typeof pg.types;
13-
export const DatabaseError: typeof pg.DatabaseError;
14-
export const escapeIdentifier: typeof pg.escapeIdentifier;
15-
export const escapeLiteral: typeof pg.escapeLiteral;
16-
export const Result: typeof pg.Result;
17-
18-
export { TypeOverrides };
1+
import * as pg from "./index.js";
192

203
declare const PG: {
214
defaults: typeof pg.defaults;
@@ -25,10 +8,46 @@ declare const PG: {
258
Connection: typeof pg.Connection;
269
types: typeof pg.types;
2710
DatabaseError: typeof pg.DatabaseError;
28-
TypeOverrides: typeof TypeOverrides;
11+
TypeOverrides: typeof pg.TypeOverrides;
2912
escapeIdentifier: typeof pg.escapeIdentifier;
3013
escapeLiteral: typeof pg.escapeLiteral;
3114
Result: typeof pg.Result;
3215
};
3316

17+
declare namespace PG {
18+
type QueryConfigValues<T> = pg.QueryConfigValues<T>;
19+
type ClientConfig = pg.ClientConfig;
20+
type ConnectionConfig = pg.ConnectionConfig;
21+
type Defaults = pg.Defaults;
22+
type PoolConfig = pg.PoolConfig;
23+
type QueryConfig<I = any[]> = pg.QueryConfig<I>;
24+
type CustomTypesConfig = pg.CustomTypesConfig;
25+
type Submittable = pg.Submittable;
26+
type QueryArrayConfig<I = any[]> = pg.QueryArrayConfig<I>;
27+
type FieldDef = pg.FieldDef;
28+
type QueryResultBase = pg.QueryResultBase;
29+
type QueryResultRow = pg.QueryResultRow;
30+
type QueryResult<R extends QueryResultRow = any> = pg.QueryResult<R>;
31+
type QueryArrayResult<R extends any[] = any[]> = pg.QueryArrayResult<R>;
32+
type Notification = pg.Notification;
33+
type ResultBuilder<R extends QueryResultRow = any> = pg.ResultBuilder<R>;
34+
type QueryParse = pg.QueryParse;
35+
type BindConfig = pg.BindConfig;
36+
type ExecuteConfig = pg.ExecuteConfig;
37+
type MessageConfig = pg.MessageConfig;
38+
type PoolOptions = pg.PoolOptions;
39+
type PoolClient = pg.PoolClient;
40+
41+
type ClientBase = pg.ClientBase;
42+
type Client = pg.Client;
43+
type Query = pg.Query;
44+
type Events = pg.Events;
45+
type Pool = pg.Pool;
46+
type Connection = pg.Connection;
47+
type DatabaseError = pg.DatabaseError;
48+
type TypeOverrides = pg.TypeOverrides;
49+
type Result = pg.Result;
50+
}
51+
52+
export * from "./index.js";
3453
export default PG;

types/pg/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ import * as Pg from ".";
326326
export const native: typeof Pg | null;
327327

328328
export { DatabaseError } from "pg-protocol";
329+
import TypeOverrides = require("./lib/type-overrides");
330+
export { TypeOverrides };
329331

330332
export class Result<R extends QueryResultRow = any> implements QueryResult<R> {
331333
command: string;

types/pg/pg-tests.mts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,10 @@ const client2 = new Client({
4242
});
4343
client2.setTypeParser(20, val => Number(val));
4444
client2.getTypeParser(20);
45+
46+
const myFunc = (c: Client) => {
47+
c.on("drain", () => {});
48+
};
49+
const myFunc2 = (c: pg.Client) => {
50+
c.on("drain", () => {});
51+
};

types/pg/pg-tests.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { connect } from "net";
22
import * as pg from "pg";
3-
import { Client, Connection, CustomTypesConfig, DatabaseError, defaults, Pool, QueryArrayConfig, types } from "pg";
3+
import {
4+
Client,
5+
Connection,
6+
CustomTypesConfig,
7+
DatabaseError,
8+
defaults,
9+
Pool,
10+
QueryArrayConfig,
11+
TypeOverrides as TypeOverridesNamed,
12+
types,
13+
} from "pg";
414
import TypeOverrides = require("pg/lib/type-overrides");
515
import { NoticeMessage } from "pg-protocol/dist/messages.js";
616

@@ -208,6 +218,9 @@ customTypeOverrides.setTypeParser(types.builtins.INT8, BigInt);
208218
const customCustomTypeOverrides = new TypeOverrides(customTypes);
209219
customTypeOverrides.setTypeParser(types.builtins.INT8, BigInt);
210220

221+
const customTypeOverridesFromNamed = new TypeOverridesNamed();
222+
customTypeOverrides.setTypeParser(types.builtins.INT8, BigInt);
223+
211224
client.connection.once("rowDescription", () => {
212225
console.log("client connection rowDescription event");
213226
});

0 commit comments

Comments
 (0)