You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
Recently I was working on some project which uses Kysely and repository pattern for calling database. Here I've created some "common" query functions.
If you look at common.ts there is an getAllWhere method which Typescript is complaining with. Here TS is trying to compare signatures and says that
Type 'ExpressionBuilder<DB, ExtractTableAlias<DB, TableName>>' is not assignable to type 'ExpressionBuilder<DB, TableName>'
I guess that's how TS works and it cannot properly assume that TableName extends keyof DB & string is actually always a table name without alias so later on it tries to infer aliased table name with ExtractTableAlias (and obviously falls back to the same value/string, because TableName cannot have alias). So it would be helpful if I could do something like:
getAllWhere<
T extends SimpleReferenceExpression<DB, TableName>,
VE extends OperandValueExpressionOrList<DB, ExtractTableAlias<DB, TableName>, T>,
QE extends ExpressionOrFactory<DB, ExtractTableAlias<DB, TableName>, SqlBool> // <=== **ExtractTableAlias** used
>(
clauses: [T, ComparisonOperatorExpression, VE][] | QE
): Promise<Selectable<Entity>[]>
Of course I could do
const query = connection.selectFrom(tableName) as QueryBuilder<DB, TableName, {}>
, or just "steal" this ExtractTableAlias type and put it inside the project, but I think that's not optimal.
Maybe there is some other way to correctly type this thing so I would be grateful for some guidance, but looking at the exposed types I cannot really see a way to do it right.
Cheers
The text was updated successfully, but these errors were encountered:
Hi!
Recently I was working on some project which uses Kysely and repository pattern for calling database. Here I've created some "common" query functions.
The problem can be seen here:
https://stackblitz.com/edit/typescript-bgfy14?file=index.ts,common.ts,package.json,tsconfig.json
If you look at
common.ts
there is angetAllWhere
method which Typescript is complaining with. Here TS is trying to compare signatures and says thatI guess that's how TS works and it cannot properly assume that
TableName extends keyof DB & string
is actually always a table name without alias so later on it tries to infer aliased table name withExtractTableAlias
(and obviously falls back to the same value/string, becauseTableName
cannot have alias). So it would be helpful if I could do something like:Of course I could do
, or just "steal" this
ExtractTableAlias
type and put it inside the project, but I think that's not optimal.Maybe there is some other way to correctly type this thing so I would be grateful for some guidance, but looking at the exposed types I cannot really see a way to do it right.
Cheers
The text was updated successfully, but these errors were encountered: