Skip to content

sql.unsafe produces results of type "any / any[]" that triggers @typescript-eslint/no-unsafe-assignment #740

@wasd171

Description

@wasd171

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()

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions