Skip to content

Commit

Permalink
Merge pull request #577 from supabase/fix/any-embeded-renaming-relation
Browse files Browse the repository at this point in the history
fix(types): inference for default any schema
  • Loading branch information
avallete authored Nov 13, 2024
2 parents fee2a82 + 74b99bb commit efa3e5c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/select-query-parser/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,9 @@ type ProcessFieldNodeWithoutSchema<Node extends Ast.FieldNode> = IsNonEmptyArray
Node['children']
> extends true
? {
[K in Node['name']]: Node['children'] extends Ast.StarNode[]
? any[]
: Node['children'] extends Ast.FieldNode[]
? {
[P in Node['children'][number] as GetFieldNodeResultName<P>]: P['castType'] extends PostgreSQLTypes
? TypeScriptTypes<P['castType']>
: any
}[]
: any[]
[K in GetFieldNodeResultName<Node>]: Node['children'] extends Ast.Node[]
? ProcessNodesWithoutSchema<Node['children']>[]
: ProcessSimpleFieldWithoutSchema<Node>
}
: ProcessSimpleFieldWithoutSchema<Node>

Expand Down
16 changes: 16 additions & 0 deletions test/select-query-parser/default-inference-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ const REST_URL = 'http://localhost:3000'
}
expectType<TypeEqual<typeof result, typeof expected>>(true)
}
// embeding renaming
{
const postgrest = new PostgrestClient(REST_URL)
const { data } = await postgrest
.from('projects')
.select('status,service:services(service_api_keys(*))')
.single()
let result: Exclude<typeof data, null>
let expected: {
status: any
service: {
service_api_keys: any[]
}[]
}
expectType<TypeEqual<typeof result, typeof expected>>(true)
}
// spread operator with stars should return any
{
const postgrest = new PostgrestClient(REST_URL)
Expand Down

0 comments on commit efa3e5c

Please sign in to comment.