-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate Prettify to get rid of intersection types #398
Comments
Hey, this looks great! Would definitely want this in the lib :) |
Amazingly, I managed to write all this text and yet forgot to include a link to the original discussion thread :D I already tried implementing this but ran into a problem. Citing myself from that thread:
+ type Prettify<T> = { [K in keyof T]: T[K] } & {};
export interface PostgrestResponseSuccess<T> extends PostgrestResponseBase {
error: null
- data: T
+ data: Prettify<T>
count: number | null
}
type Prettify<T> = { [K in keyof T]: T[K] } & {};
export type PostgrestSingleResponse<T> =
- | PostgrestResponseSuccess<T>
+ | PostgrestResponseSuccess<Prettify<T>>
| PostgrestResponseFailure
Can you help me out with where to put |
I see, so I guess it only works on one layer. Can you try this diff? diff --git a/src/select-query-parser.ts b/src/select-query-parser.ts
index dc90ec7..5f8c5a7 100644
--- a/src/select-query-parser.ts
+++ b/src/select-query-parser.ts
@@ -1,6 +1,6 @@
// Credits to @bnjmnt4n (https://www.npmjs.com/package/postgrest-query)
-import { GenericSchema } from './types'
+import { GenericSchema, Prettify } from './types'
type Whitespace = ' ' | '\n' | '\t'
@@ -342,7 +342,7 @@ type GetResultHelper<
? GetResultHelper<Schema, Row, [], ConstructFieldDefinition<Schema, Row, R> & Acc>
: Fields extends [infer R, ...infer Rest]
? GetResultHelper<Schema, Row, Rest, ConstructFieldDefinition<Schema, Row, R> & Acc>
- : Acc
+ : Prettify<Acc>
/**
* Constructs a type definition for an object based on a given PostgREST query.
diff --git a/src/types.ts b/src/types.ts
index f9bbf66..f2464d3 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -69,3 +69,5 @@ export type GenericSchema = {
Views: Record<string, GenericView>
Functions: Record<string, GenericFunction>
}
+
+export type Prettify<T> = { [K in keyof T]: T[K] } & {} |
* Prettify intersected types when selecting multiple columns Resolves #398 * update type test --------- Co-authored-by: Bobbie Soedirgo <[email protected]>
🎉 This issue has been resolved in version 1.4.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Bug report
Hi, this is an improvement suggestion and I have first opened a documentation thread for this but it has not seen any activity since I opened it last week so I figure I'd reopen it here to give it a chance to get some attention.
Describe the bug
When using Postgrest
.select('a,b,c')
we get an intersection type back:{ a: type; } & { b: type } & { c: type }
.To Reproduce
index.test-d.ts
:data
to see its real typeExpected behavior
I am hoping we can incorporate this to make the type non-intersected:
Credit goes to https://twitter.com/mattpocockuk/status/1622730173446557697.
Screenshots
Currently we get this inferred type when hovering over
data
fromselect
:With
Prettify
hovering over theselect
responsedata
we'll see this inferred type:The text was updated successfully, but these errors were encountered: