Skip to content

ESLint @typescript-eslint/no-unsafe-argument with serializerCompiler #212

@Ephasme

Description

@Ephasme

Bug Report: ESLint @typescript-eslint/no-unsafe-argument with serializerCompiler

Environment:

  • fastify-type-provider-zod: 6.0.0
  • Fastify: 5.6.0
  • TypeScript: 5.x
  • ESLint: typescript-eslint strict config

Issue:
When using serializerCompiler from fastify-type-provider-zod, ESLint throws: Unsafe argument of type error typed assigned to a parameter of type FastifySerializerCompiler

Code that triggers the issue:

import { validatorCompiler, serializerCompiler } from 'fastify-type-provider-zod';

function routesPlugin(fastify: FastifyInstance) {
    fastify.setValidatorCompiler(validatorCompiler); // ✅ Works fine
    fastify.setSerializerCompiler(serializerCompiler); // ❌ ESLint error
}

Root cause:
The issue stems from the union type in serializerCompiler:

FastifySerializerCompiler<$ZodType | { properties: $ZodType; }>

While validatorCompiler uses a simple type:

FastifySchemaCompiler<$ZodType>

Workarounds:

  • Disable ESLint rule: // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
  • Type assertion: serializerCompiler as FastifySerializerCompiler<any>

Expected behavior:
serializerCompiler should work without ESLint warnings, similar to validatorCompiler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions