Skip to content

Commit 74b99bb

Browse files
committed
fix(types): inference for default any schema
1 parent fee2a82 commit 74b99bb

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

Diff for: src/select-query-parser/result.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,9 @@ type ProcessFieldNodeWithoutSchema<Node extends Ast.FieldNode> = IsNonEmptyArray
7878
Node['children']
7979
> extends true
8080
? {
81-
[K in Node['name']]: Node['children'] extends Ast.StarNode[]
82-
? any[]
83-
: Node['children'] extends Ast.FieldNode[]
84-
? {
85-
[P in Node['children'][number] as GetFieldNodeResultName<P>]: P['castType'] extends PostgreSQLTypes
86-
? TypeScriptTypes<P['castType']>
87-
: any
88-
}[]
89-
: any[]
81+
[K in GetFieldNodeResultName<Node>]: Node['children'] extends Ast.Node[]
82+
? ProcessNodesWithoutSchema<Node['children']>[]
83+
: ProcessSimpleFieldWithoutSchema<Node>
9084
}
9185
: ProcessSimpleFieldWithoutSchema<Node>
9286

Diff for: test/select-query-parser/default-inference-d.ts

+16
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ const REST_URL = 'http://localhost:3000'
3535
}
3636
expectType<TypeEqual<typeof result, typeof expected>>(true)
3737
}
38+
// embeding renaming
39+
{
40+
const postgrest = new PostgrestClient(REST_URL)
41+
const { data } = await postgrest
42+
.from('projects')
43+
.select('status,service:services(service_api_keys(*))')
44+
.single()
45+
let result: Exclude<typeof data, null>
46+
let expected: {
47+
status: any
48+
service: {
49+
service_api_keys: any[]
50+
}[]
51+
}
52+
expectType<TypeEqual<typeof result, typeof expected>>(true)
53+
}
3854
// spread operator with stars should return any
3955
{
4056
const postgrest = new PostgrestClient(REST_URL)

0 commit comments

Comments
 (0)