This is the current definition of the QuerySqlToken
|
export type QuerySqlToken< |
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any |
|
T extends StandardSchemaV1 = StandardSchemaV1<any, any>, |
|
> = { |
|
readonly parser: T; |
|
readonly sql: string; |
|
readonly type: typeof tokens.QueryToken; |
|
readonly values: readonly PrimitiveValueExpression[]; |
|
}; |
And the current definition of the sql.unsafe:
|
unsafe: (parts, ...args) => { |
|
return Object.freeze({ |
|
...createFragment(parts, args), |
|
parser: z.any(), |
|
type: QueryToken, |
|
}); |
|
}, |
As a result, queries that are constructed via the sql.unsafe tags return results of any / any[], etc. A few releases ago we were getting readonly any[] types which did not trigger the @typescript-eslint/no-unsafe-assignment rule
Desired Behavior
I would prefer if slonik could return results of unknown / unknown[] types for such queries. This would still force the developer to do the runtime type validation (we use typebox instead of zod) but with the additional type-checking upsides
Implementation
It would probably be enough to do the following:
// sql-tag/src/types.ts
T extends StandardSchemaV1 = StandardSchemaV1<unknown, unknown> // instead of T extends StandardSchemaV1 = StandardSchemaV1<any, any>
// sql-tag/src/factories/createSqlTag.ts
parser: z.unknown() // instead of parser: z.any()
This is the current definition of the
QuerySqlTokenslonik/packages/sql-tag/src/types.ts
Lines 65 to 73 in a9a02c0
And the current definition of the
sql.unsafe:slonik/packages/sql-tag/src/factories/createSqlTag.ts
Lines 234 to 240 in a9a02c0
As a result, queries that are constructed via the
sql.unsafetags return results ofany/any[], etc. A few releases ago we were gettingreadonly any[]types which did not trigger the@typescript-eslint/no-unsafe-assignmentruleDesired Behavior
I would prefer if slonik could return results of
unknown/unknown[]types for such queries. This would still force the developer to do the runtime type validation (we use typebox instead of zod) but with the additional type-checking upsidesImplementation
It would probably be enough to do the following: