Skip to content

fix: ajv options type validation#6437

Merged
Eomm merged 6 commits intofastify:mainfrom
gianmarco27:fix/ajv-options-type-validation
Jan 3, 2026
Merged

fix: ajv options type validation#6437
Eomm merged 6 commits intofastify:mainfrom
gianmarco27:fix/ajv-options-type-validation

Conversation

@gianmarco27
Copy link
Contributor

First of all: Happy holidays! :)

The reason for this PR stems from #6223

Below i enumerate the two issues i found, with a bullet list:

  • Currently, in a TS project if I try to use the onCreate ajv option I still get met with a typescript error (requiring a ts-expect-error), as such option is not defined in the exposed fastify type, although made available by fastify/ajv-compiler
    (My suggested fix is to mirror the entire ajv options field type definition from the ajv-compiler itself, as fastify already proxies the object to it in the js implementation, this way the type definitions remain transparent to the implementation and future updates)

  • Additionally I have added also a test to showcase an error in the current ajv plugin type definition where the override of the plugin types is too generous, and allows for plugins to be passed, that would break the ajv plugin definition fluent standard, so if i provide my own validatorCompiler, leveraging this Ajv feature, i get no warning from TS to alert me that perhaps these plugins might break my implementation because they are not returning the Ajv instance.
    (Again proxying the type directly from the library solves this as it enforces the Ajv plugin definition)

I have committed types tests showcasing the 2 different use cases above, that would fail with the current type definition and following them up with the related fix, together with the dependency update of fastify/ajv-compiler that is required to apply these improvements.

Lastly I have added a small enrichment in docs for the ajv options and a little fix in jsdocs for fastify which i found while browsing the js code.

Checklist

@github-actions github-actions bot added documentation Improvements or additions to documentation typescript TypeScript related labels Jan 2, 2026
Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing to revert but LGTM

@gianmarco27
Copy link
Contributor Author

Are the markdown linting errors to be expected? I can have a go at fixing them if you wish.

@gianmarco27 gianmarco27 requested a review from gurgunday January 2, 2026 20:56
@gianmarco27 gianmarco27 force-pushed the fix/ajv-options-type-validation branch from 7fd86fb to 6f46b78 Compare January 2, 2026 21:00
Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

thanks for the changes, and happy holidays :)

Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint failure not related to this PR

maybe a GHA update gone wrong

@Eomm Eomm merged commit 1d5f8ae into fastify:main Jan 3, 2026
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation typescript TypeScript related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants