-
-
Notifications
You must be signed in to change notification settings - Fork 120
Open
Description
Bug Description
The ajvFilePlugin type definition is incompatible with Fastify's ajv.plugins option, causing TypeScript errors when registering the plugin.
Current Type
export function ajvFilePlugin (ajv: any): voidExpected Type
export function ajvFilePlugin (ajv: Ajv): AjvSteps to Reproduce
import fastify from 'fastify'
import { fastifyMultipart, ajvFilePlugin } from '@fastify/multipart'
const app = fastify({
ajv: {
plugins: [ajvFilePlugin] // TypeScript error here
}
})
app.register(fastifyMultipart)Error Message
error TS2769: No overload matches this call.
The last overload gave the following error.
Type '(ajv: any) => void' is not assignable to type 'Plugin<unknown> | [Plugin<unknown>, unknown]'.
Type '(ajv: any) => void' is not assignable to type 'Plugin<unknown>'.
Type 'void' is not assignable to type 'Ajv'.
Root Cause
Fastify's ajv.plugins option expects Plugin<unknown> type from @fastify/ajv-compiler, which is defined as:
export interface Plugin<Opts> {
(ajv: Ajv, options?: Opts): Ajv; // Must return Ajv
[prop: string]: any;
}The actual implementation in index.js correctly returns Ajv:
function ajvFilePlugin (ajv) {
return ajv.addKeyword({...}) // addKeyword returns Ajv
}But the type definition incorrectly declares the return type as void.
Proposed Fix
- Add
ajvto devDependencies for type definitions - Update
types/index.d.ts:
import type Ajv from 'ajv'
// ...
export function ajvFilePlugin (ajv: Ajv): AjvEnvironment
@fastify/multipart: 9.4.0fastify: 5.7.4- TypeScript: 5.8.3
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels