K
Kysely11mo ago
Robin

Type errors after 0.27.1 upgrade

After upgrading to the lastest verision, I've got a couple of type errors that I'm not sure how to resolve. They are both the same kind of error, I have a custom WHERE IN expression:
eb(
"objects.type",
"in",
sql.raw(
`(${ALLOWED_OBJECT_TYPES.map((o) => `'${o}'`).join(",")})`,
),
),
eb(
"objects.type",
"in",
sql.raw(
`(${ALLOWED_OBJECT_TYPES.map((o) => `'${o}'`).join(",")})`,
),
),
Which gives me this error:
Argument of type 'RawBuilder<unknown>' is not assignable to parameter of type 'OperandValueExpressionOrList<DB & { target_objects: { object_id: string; }; } & { objects: { id: string; oid: number; schema_id: string; name: string; type: string; owner_id: string; privileges: string[] | null; }; } & { transitive_dependencies: { ...; }; } & { ...; } & { ...; } & { ...; } & { ...; }, "objects" | "s...'.
Property 'isSelectQueryBuilder' is missing in type 'RawBuilder<unknown>' but required in type 'SelectQueryBuilderExpression<Record<string, string | null>>'.

60 sql.raw(
~~~~~~~~
61 `(${ALLOWED_OBJECT_TYPES.map((o) => `'${o}'`).join(",")})`,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62 ),
~~~~~~~~~~~~~~~
Argument of type 'RawBuilder<unknown>' is not assignable to parameter of type 'OperandValueExpressionOrList<DB & { target_objects: { object_id: string; }; } & { objects: { id: string; oid: number; schema_id: string; name: string; type: string; owner_id: string; privileges: string[] | null; }; } & { transitive_dependencies: { ...; }; } & { ...; } & { ...; } & { ...; } & { ...; }, "objects" | "s...'.
Property 'isSelectQueryBuilder' is missing in type 'RawBuilder<unknown>' but required in type 'SelectQueryBuilderExpression<Record<string, string | null>>'.

60 sql.raw(
~~~~~~~~
61 `(${ALLOWED_OBJECT_TYPES.map((o) => `'${o}'`).join(",")})`,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62 ),
~~~~~~~~~~~~~~~
I assume I need to pass a type to sql.raw, but I haven't been able to figure out what that type should be.
Solution:
yeah, I just realized that, I don't need sql.raw at all
Jump to solution
9 Replies
thelinuxlich
thelinuxlich11mo ago
The type should be the same of objects.type[]
Robin
RobinOP11mo ago
as in, string[]? that doesn't seem to work, maybe I'm not following I was looking through the code to see if there was something like an InExpression type or something, but I didn't find anything like that.
thelinuxlich
thelinuxlich11mo ago
Btw do you really need a sql.raw? What's stopping you from just passing allowed_object_types
Solution
Robin
Robin11mo ago
yeah, I just realized that, I don't need sql.raw at all
Robin
RobinOP11mo ago
That avoids the issue, thanks!
Robin
RobinOP11mo ago
oh, I just ran into another case where I can't avoid sql.raw:
.where(
(eb) => eb("mal.finished_at", "-", eb.ref("mal.began_at")),
">=",
sql`'${sql.raw(`${minDuration}`)} MILLISECONDS'`,
)
.where(
(eb) => eb("mal.finished_at", "-", eb.ref("mal.began_at")),
">=",
sql`'${sql.raw(`${minDuration}`)} MILLISECONDS'`,
)
thelinuxlich
thelinuxlich11mo ago
I think it should be sql<Date>${minDuration} MILLISECONDS
Robin
RobinOP11mo ago
sure enough, thanks!
Igal (mobile)
Igal (mobile)11mo ago
it was mentioned in the release notes that sql template tag will require typing now.
Want results from more Discord servers?
Add your server