Is it possible to create generic schema proxy?

<TSchema extends Record<string, unknown>, TDb extends PostgresJsDatabase<TSchema>>
<TSchema extends Record<string, unknown>, TDb extends PostgresJsDatabase<TSchema>>
something like that should be ok, but I got errors in type:
type FindFn<TK extends keyof typeof db.query = keyof typeof db.query> = (
...args:
| Parameters<(typeof db.query)[TK]['findFirst']>
| Parameters<(typeof db.query)[TK]['findMany']>
) =>
| ReturnType<(typeof db.query)[TK]['findFirst']>
| ReturnType<(typeof db.query)[TK]['findMany']>;
type FindFn<TK extends keyof typeof db.query = keyof typeof db.query> = (
...args:
| Parameters<(typeof db.query)[TK]['findFirst']>
| Parameters<(typeof db.query)[TK]['findMany']>
) =>
| ReturnType<(typeof db.query)[TK]['findFirst']>
| ReturnType<(typeof db.query)[TK]['findMany']>;
1 Reply
Mario564
Mario5643mo ago
This use case doesn't have a simple solution; for now, you do have to use plenty of util types to get your desired result. I recommend extracting these into other generic types to simplify the definitions

Did you find this page helpful?