Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit 8e0a0fc

Browse files
committed
chore: add comment
1 parent 6b26db4 commit 8e0a0fc

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,12 @@ type MergeExplicit<New, Row> = {
161161
}
162162

163163
type MergeDeep<New, Row> = Simplify<
164-
MergeExplicit<New, Row> & (string extends keyof Row ? { [K: string]: Row[string] } : {})
164+
MergeExplicit<New, Row> &
165+
// Intersection here is to restore dynamic keys into the merging result
166+
// eg:
167+
// {[key: number]: string}
168+
// or Record<string, number | null>
169+
(string extends keyof Row ? { [K: string]: Row[string] } : {})
165170
>
166171

167172
// Helper to check if a type is a plain object (not an array)

test/override-types.test-d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
247247
bar: { baz: number }
248248
en: 'ONE' | 'TWO' | 'THREE'
249249
record: Record<string, Json | undefined> | null
250+
recordNumber: Record<number, Json | undefined> | null
250251
qux: boolean
251252
}
252253
age_range: unknown
@@ -277,6 +278,7 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
277278
bar: { baz: number }
278279
en: 'ONE' | 'TWO' | 'THREE'
279280
record: Record<string, Json | undefined> | null
281+
recordNumber: Record<number, Json | undefined> | null
280282
qux: boolean
281283
} | null
282284
age_range: unknown
@@ -345,6 +347,7 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
345347
bar: { baz: number; newBaz: string }
346348
en: 'FOUR' // Overridden enum value
347349
record: Record<string, Json | undefined> | null
350+
recordNumber: Record<number, Json | undefined> | null
348351
}
349352
age_range: unknown
350353
catchphrase: unknown
@@ -359,7 +362,7 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
359362
const result = await postgrest
360363
.from('users')
361364
.select()
362-
.overrideTypes<{ data: { record: { baz: 'foo' } } }[]>()
365+
.overrideTypes<{ data: { record: { baz: 'foo' }; recordNumber: { bar: 'foo' } } }[]>()
363366
if (result.error) {
364367
throw new Error(result.error.message)
365368
}
@@ -379,6 +382,10 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
379382
[x: string]: Json | undefined
380383
baz: 'foo'
381384
}
385+
recordNumber: {
386+
[x: number]: Json | undefined
387+
bar: 'foo'
388+
}
382389
}
383390
age_range: unknown
384391
catchphrase: unknown

test/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type CustomUserDataType = {
77
}
88
en: 'ONE' | 'TWO' | 'THREE'
99
record: Record<string, Json | undefined> | null
10+
recordNumber: Record<number, Json | undefined> | null
1011
}
1112

1213
export type Database = {

0 commit comments

Comments
 (0)