-
Notifications
You must be signed in to change notification settings - Fork 384
Open
Labels
bugSomething isn't workingSomething isn't workingtypescriptRelated to TypescriptRelated to Typescript
Description
Versions
- Kysely: 0.28.9
- TypeScript: 5.9.3
- Node: (not relevant)
Repro
npm i kysely typescript- Create tsconfig.json:
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"noEmit": true,
"types": []
}
}
- Create repro.ts:
import type { SelectQueryBuilder } from "kysely";
interface DB {
person: { id: number; name: string };
pet: { id: number; owner_id: number };
}
// Attempt at a reusable helper that requires the "person" table to be present.
function wherePersonHasName<DBT extends DB, TB extends keyof DBT, O>(
qb: SelectQueryBuilder<DBT, "person" | TB, O>,
): SelectQueryBuilder<DBT, "person" | TB, O> {
// Expect this to be valid because "person" is explicitly included in TB.
return qb.where("person.name", "=", "alice");
}
// Usage with a concrete builder that *does* include "person".
declare const concreteQuery: SelectQueryBuilder<DB, "person" | "pet", { id: number }>;
wherePersonHasName(concreteQuery);
npx tsc -p tsconfig.json
Actual
TS2345: Argument of type 'string' is not assignable to parameter of type 'ReferenceExpression<DBT, TB | "person">'.
Expected
The helper should typecheck because "person" is explicitly included in TB and "person.name" is a valid column reference.
Notes
- Inlining the same
where("person.name", ...)at the call site compiles. - The failure appears related to
SelectQueryBuilderbeing invariant inTB/ReferenceExpressionin a generic context, which makes it hard to write reusable, type-safe query helpers without assertions orsql.ref. - This blocks DRY filters that require certain tables to be present.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingtypescriptRelated to TypescriptRelated to Typescript