Error: ... not assignable to parameter of type SelectedFields

I am trying to build a wrapper around drizzle select and this is being hard to achieve. What do I want? I want to create a wrapper that receives a where clause and SelectedFields, but I want the type-safety in order to suggest only valid columns to the user. I have something like this:
get<TWhere>(
where: SQL<TWhere>,
select?: Record<keyof typeof schema.subAccountDetail.$inferSelect, unknown>
) {
return this.db
.select(select)
.from(schema.subAccountDetail)
.where(where);
}
get<TWhere>(
where: SQL<TWhere>,
select?: Record<keyof typeof schema.subAccountDetail.$inferSelect, unknown>
) {
return this.db
.select(select)
.from(schema.subAccountDetail)
.where(where);
}
But this is getting me to this error:
Diagnostics:
1. Argument of type 'Record<"id" | "description" | "createdAt" | "updatedAt" | "deletedAt" | "dueDate" | "value" | "externalCreatedBy" | "externalChangedBy" | "originalValue" | "idPerfil" | "idPerfilChangedBy" | "idAccountDetail" | "idSubAccount", unknown>' is not assignable to parameter of type 'SelectedFields'.
Property 'id' is incompatible with index signature.
Type 'unknown' is not assignable to type 'SQL<unknown> | Aliased<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}> | PgTable<TableConfig> | SelectedFieldsFlat<...>'. [2345]
Diagnostics:
1. Argument of type 'Record<"id" | "description" | "createdAt" | "updatedAt" | "deletedAt" | "dueDate" | "value" | "externalCreatedBy" | "externalChangedBy" | "originalValue" | "idPerfil" | "idPerfilChangedBy" | "idAccountDetail" | "idSubAccount", unknown>' is not assignable to parameter of type 'SelectedFields'.
Property 'id' is incompatible with index signature.
Type 'unknown' is not assignable to type 'SQL<unknown> | Aliased<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}> | PgTable<TableConfig> | SelectedFieldsFlat<...>'. [2345]
If I change from unknown to any, everything works fine. What I really want, is to use $inferSelect type so the method becomes type-safe with selects columns. How can I do that?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server