kysely icon indicating copy to clipboard operation
kysely copied to clipboard

Allow `string` argument when `regexp`- or `like`-ing an enum column

Open twiddler opened this issue 10 months ago • 1 comments

When filtering an enum column, e.g.

interface Database {
  Pet: {
    species: "dog" | "cat" | "hamster";
  };
}

with "regexp" or "like"

db.selectFrom("Pet")
  .where("species", "regexp", "ste") // ❌ Argument of type '"ste"' is not assignable to parameter of type 'OperandValueExpressionOrList<Database, "Pet", "species">'.(2345)
  .where("species", "like", "%ste%") // ❌ Argument of type '"%ste%"' is not assignable to parameter of type 'OperandValueExpressionOrList<Database, "Pet", "species">'.(2345)

the types leading to the type errors above seem too strict to me.

What do you think about broadening the type to string for the right-hand side argument of "regexp" and "like"?

Playground link

twiddler avatar Jan 22 '25 11:01 twiddler