Skip to content

Commit 92cb08f

Browse files
authored
fix Buffer breaking types in non-Node TypeScript environments. (#1542)
1 parent 84710b2 commit 92cb08f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/util/type-utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,12 @@ export type ShallowDehydrateValue<T> = T extends null | undefined
250250
? never
251251
: string)
252252

253-
export type StringsWhenDataTypeNotAvailable = Date | Buffer | ArrayBuffer
253+
export type StringsWhenDataTypeNotAvailable =
254+
| Date
255+
// Many Node.js drivers return `Buffer` by default for some column data types.
256+
// Buffer is a subclass of `Uint8Array`. `Buffer` doesn't exist in non-Node TypeScript
257+
// environments - and results in `any` or a compilation error if used.
258+
| Uint8Array
254259

255260
export type NumbersWhenDataTypeNotAvailable = bigint | NumericString
256261

test/typings/test-d/postgres-json.test-d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ async function testPostgresJsonSelects(db: Kysely<Database>) {
4646
modified_at: eb.ref('modified_at'),
4747
people_with_same_name_by_2050: sql<bigint>`custom_function(first_name)`,
4848
people_with_same_name_by_2050_str: sql<NumericString>`custom_function(first_name)::text`,
49+
binary_thing: sql<Buffer>`another_custom_function()`,
4950
}).as('name'),
5051

5152
// Nest other people with same first name.
@@ -90,6 +91,7 @@ async function testPostgresJsonSelects(db: Kysely<Database>) {
9091
modified_at: string
9192
people_with_same_name_by_2050: number
9293
people_with_same_name_by_2050_str: number
94+
binary_thing: string
9395
}
9496
people_same_first_name: {
9597
id: number

0 commit comments

Comments
 (0)