fix: correct ajvFilePlugin type to be compatible with Fastify ajv.plugins#606
fix: correct ajvFilePlugin type to be compatible with Fastify ajv.plugins#606nahyeongjin1 wants to merge 10 commits intofastify:mainfrom
Conversation
mcollina
left a comment
There was a problem hiding this comment.
Can you ads a test for this type? We use tsd.
|
Added type test in Note: The tsd tests are located in Also noticed the filename has a typo: |
This also means I think the best fix would be to follow the pattern from other
|
|
Thanks @mrazauskas for the suggestion! Done. Moved all type test files to The |
|
Thanks! I checked out this branch. All works as expected. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a TypeScript type incompatibility between ajvFilePlugin and Fastify's ajv.plugins option. The plugin was incorrectly typed as returning void when it should return Ajv to satisfy Fastify's Plugin<unknown> interface requirement.
Changes:
- Updated
ajvFilePlugintype signature to acceptAjvinstead ofanyand returnAjvinstead ofvoid - Added
ajvv8.17.1 to devDependencies for type definitions - Fixed test file organization by moving from
types/totest/types/and correcting a filename typo ("avj" → "ajv")
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| types/index.d.ts | Updated ajvFilePlugin type signature and added Ajv type import |
| package.json | Added ajv to devDependencies for type definitions |
| test/types/ajv-plugin.test-d.ts | New comprehensive test file for ajvFilePlugin compatibility with proper path |
| types/avj-plugin.test-d.ts | Removed old test file with typo in filename |
| test/types/named-import.test-d.ts | Updated import path from '..' to '../..' to reflect new test location |
| test/types/index.test-d.ts | Updated import path from '..' to '../..' to reflect new test location |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Ci looks red |
751fbec to
431f3ee
Compare
|
Fixed the CI failures:
Could you re-run the CI? Thanks! |
test/multipart-ajv-file.test.js
Outdated
| * requestBody.required (fastify/fastify-swagger#903), making the exact | ||
| * shape version-dependent. | ||
| */ | ||
| // t.assert.deepStrictEqual(fastify.swagger().paths, { |
There was a problem hiding this comment.
instead of commenting it out, could you check other parts of the requestBody like the content?
Additionally, you should be able also to check the operation id.
There was a problem hiding this comment.
@nahyeongjin1
nit: shouldn't you remove this huge comment and keep just the one below?
There was a problem hiding this comment.
Done, removed the commented-out block 👍
|
@ilteoood
|
|
Fixed the Node.js 20 CI failure: glob quotes in Verified all tests pass on Node.js 20, 22, and 24. |
|
@ilteoood I've added a fix using exponential backoff retry for the file deletion check. |
…gins The ajvFilePlugin return type was incorrectly declared as void instead of Ajv.This caused TypeScript errors when using the plugin with Fastify ajv.plugins option Changes: - Add ajv to devDependencies for type definitions - Import Ajv type in types/index.d.ts - Change ajvFilePlugin signature from (ajv: any): void to (ajv: Ajv): Ajv Fixes fastify#605
Added expectType<Ajv> assertion to verify ajvFilePlugin correctly returns Ajv instance.
- Move type test files from types/ to test/types/ - Fix filename typo: avj-plugin.test-d.ts -> ajv-plugin.test-d.ts - Update import paths from '..' to '../..'
Node.js 22+ test runner auto-discovers .ts files in the test/ directory, causing tsd type test files (.test-d.ts) to be executed as regular tests. Changes: - Specify explicit glob pattern to only run .test.js files - Narrow tsd directory from test/ to test/types/ for precise targeting - Update swagger schema assertion to include requestBody.required field added by newer @fastify/swagger versions
Only verify ajvFilePlugin's core behavior (isFile -> string/binary) instead of the full paths object. The requestBody.required field was introduced in @fastify/swagger v9.7.0 (fastify/fastify-swagger#903), making the exact shape version-dependent.
74f4f71 to
6fee76d
Compare
|
Rebased on main. If you'd prefer the #607 approach (full assertion with |
Summary
ajvFilePlugintype definition to be compatible with Fastify'sajv.pluginsoptionajvto devDependencies for type definitionsvoidtoAjvProblem
The
ajvFilePluginwas typed as(ajv: any): void, but Fastify'sajv.pluginsexpectsPlugin<unknown>which requires returningAjv.Solution
Test plan
npm run test:typescriptpassesFixes #605