Skip to content

Fix TS2769 build error in node renderer onFile callback#2469

Merged
AbanoubGhadban merged 1 commit intomasterfrom
fix/2467-check-bundle-size-ci
Feb 22, 2026
Merged

Fix TS2769 build error in node renderer onFile callback#2469
AbanoubGhadban merged 1 commit intomasterfrom
fix/2467-check-bundle-size-ci

Conversation

@AbanoubGhadban
Copy link
Copy Markdown
Collaborator

@AbanoubGhadban AbanoubGhadban commented Feb 22, 2026

Summary

  • Removes the explicit this: FastifyRequest (Http2Server-typed) annotation from the onFile callback in worker.ts, which was incompatible with @fastify/multipart's type definitions that expect the default RawServerDefault FastifyRequest
  • This fixes the TS2769: No overload matches this call error that broke pnpm build and pnpm install on fresh runners (where the prepare script runs tsc)

Fixes #2467

Test plan

  • pnpm install succeeds (triggers preparetsc)
  • pnpm build succeeds in packages/react-on-rails-pro-node-renderer
  • pnpm type-check succeeds in packages/react-on-rails-pro-node-renderer
  • CI check-bundle-size job passes on a fresh runner (no cached lib/)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved internal type annotations for file handling functionality. No user-facing changes or functionality modifications.

The `onFile` callback in worker.ts annotated `this` with the local
Http2Server-typed `FastifyRequest`, but @fastify/multipart types expect
the default (RawServerDefault) `FastifyRequest`. This caused a type
mismatch (`IncomingMessage` missing `authority`, `scheme`, `stream`
from `Http2ServerRequest`) that broke `pnpm build` and `pnpm install`.

Remove the explicit `this: FastifyRequest` annotation so TypeScript
contextually infers the correct type from the plugin's definition.

Fixes #2467

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 22, 2026

No actionable comments were generated in the recent review. 🎉


Walkthrough

The pull request fixes a TypeScript type annotation incompatibility in the multipart file handler. The explicit this: FastifyRequest type parameter was removed from the onFile function signature, resolving a TS2769 compilation error while preserving the runtime behavior through proper binding.

Changes

Cohort / File(s) Summary
Type Annotation Fix
packages/react-on-rails-pro-node-renderer/src/worker.ts
Removed explicit this: FastifyRequest type annotation from the onFile handler in the multipart file registration. Added clarifying comment that the function binding to FastifyRequest context is preserved at runtime. Resolves TypeScript compilation error without altering functional behavior.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related issues

Poem

🐰 A type annotation cleared with care,
The this was bound, though not declared,
The compiler smiles, no error in sight,
Runtime and types now both feel right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: fixing a TS2769 build error in the onFile callback of the node renderer, which is the core purpose of this PR.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #2467: it resolves the TS2769 type error by removing the explicit 'this: FastifyRequest' annotation, enabling successful compilation without the Http2 type conflict.
Out of Scope Changes check ✅ Passed The changes are narrowly scoped to fixing the TS2769 error in the onFile callback signature; no unrelated modifications or scope creep is present in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/2467-check-bundle-size-ci

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Feb 22, 2026

Review

Overall: Correct fix, approve with one note

The root cause is clear: the local FastifyRequest alias (in worker/types.ts) is parameterized with Http2Server, but @fastify/multipart's onFile option types this using RawServerDefault. These two generic instantiations are structurally incompatible, so the explicit this: FastifyRequest annotation caused TS2769: No overload matches this call.

Removing the annotation lets TypeScript infer this from the plugin's overload signature, which is the correct minimal fix.

What holds the fix together:

  • The declare module 'fastify' { interface FastifyRequest { uploadDir: string } } module augmentation (lines 51–56) patches the global FastifyRequest interface, so whichever concrete server type the plugin resolves to, the uploadDir property is still present and type-checked.
  • The runtime guard typeof this?.uploadDir !== 'string' (line 182) provides a safety net if this binding ever behaves unexpectedly.

Minor note worth tracking:
Without the explicit annotation TypeScript's knowledge of this inside the callback is now driven entirely by the plugin's declared overload. If a future upgrade of @fastify/multipart types this as unknown or any in that overload, the this.uploadDir accesses would silently lose type-checking. The runtime guard above mitigates the risk, but it's worth a quick check after any @fastify/multipart version bump to confirm tsc --strict still catches bad accesses.

The explanatory comment added alongside the change is helpful for future maintainers.

async onFile(this: FastifyRequest, part) {
// Note: do NOT annotate `this` with the local Http2Server-typed FastifyRequest;
// the plugin types expect the default (RawServerDefault) FastifyRequest.
async onFile(part) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fix is correct. One thing worth noting for future maintainers: this here is now typed by @fastify/multipart's overload rather than the local Http2Server-parameterized alias. That's safe today because the global module augmentation (declare module 'fastify' { interface FastifyRequest { uploadDir: string } }, lines 51–56) patches whichever concrete FastifyRequest the plugin resolves to.

If a future @fastify/multipart upgrade ever changes its onFile overload to type this as unknown or any, the this.uploadDir accesses below would silently lose type coverage. The runtime guard on line 182 mitigates that, but a quick tsc check after any multipart version bump is worthwhile.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Feb 22, 2026

Greptile Summary

Fixes TypeScript build error (TS2769) caused by incompatible type annotation on the onFile callback in worker.ts:181.

The issue occurred because the local FastifyRequest type (from worker/types.ts:11) is parameterized with Http2Server, but @fastify/multipart's type definitions expect the callback's this context to be the default FastifyRequest<RouteGenericInterface, RawServerDefault>. This mismatch broke pnpm build and pnpm install (via the prepare script) on fresh runners.

Solution: Removed the explicit this: FastifyRequest type annotation and added a clarifying comment. The callback still uses a regular function (not an arrow function) so @fastify/multipart can bind this correctly in attachFieldsToBody mode. A runtime assertion on line 182 validates that this is correctly bound.

Key changes:

  • Removed this: FastifyRequest parameter from onFile callback
  • Added explanatory comment about avoiding local Http2Server-typed FastifyRequest
  • Functionality remains unchanged; runtime behavior is identical

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is a minimal, surgical change that removes a type annotation causing a TypeScript compilation error. The runtime behavior is unchanged - the callback still uses a regular function so @fastify/multipart can bind this, and line 182 validates the binding at runtime. The fix is confirmed by the test plan showing successful builds, and existing tests (particularly uploadRaceCondition.test.ts) verify the upload functionality works correctly.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react-on-rails-pro-node-renderer/src/worker.ts Removes incompatible this: FastifyRequest type annotation from onFile callback, fixing TS2769 build error

Last reviewed commit: ee46f99

@AbanoubGhadban AbanoubGhadban merged commit 3973859 into master Feb 22, 2026
35 of 36 checks passed
@AbanoubGhadban AbanoubGhadban deleted the fix/2467-check-bundle-size-ci branch February 22, 2026 08:38
AbanoubGhadban added a commit that referenced this pull request Feb 25, 2026
## Summary
- Removes the explicit `this: FastifyRequest` (Http2Server-typed)
annotation from the `onFile` callback in `worker.ts`, which was
incompatible with `@fastify/multipart`'s type definitions that expect
the default `RawServerDefault` `FastifyRequest`
- This fixes the `TS2769: No overload matches this call` error that
broke `pnpm build` and `pnpm install` on fresh runners (where the
`prepare` script runs `tsc`)

Fixes #2467

## Test plan
- [x] `pnpm install` succeeds (triggers `prepare` → `tsc`)
- [x] `pnpm build` succeeds in
`packages/react-on-rails-pro-node-renderer`
- [x] `pnpm type-check` succeeds in
`packages/react-on-rails-pro-node-renderer`
- [ ] CI `check-bundle-size` job passes on a fresh runner (no cached
`lib/`)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Refactor**
* Improved internal type annotations for file handling functionality. No
user-facing changes or functionality modifications.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Claude Opus 4.6 <[email protected]>
AbanoubGhadban added a commit that referenced this pull request Mar 7, 2026
## Summary
- Removes the explicit `this: FastifyRequest` (Http2Server-typed)
annotation from the `onFile` callback in `worker.ts`, which was
incompatible with `@fastify/multipart`'s type definitions that expect
the default `RawServerDefault` `FastifyRequest`
- This fixes the `TS2769: No overload matches this call` error that
broke `pnpm build` and `pnpm install` on fresh runners (where the
`prepare` script runs `tsc`)

Fixes #2467

## Test plan
- [x] `pnpm install` succeeds (triggers `prepare` → `tsc`)
- [x] `pnpm build` succeeds in
`packages/react-on-rails-pro-node-renderer`
- [x] `pnpm type-check` succeeds in
`packages/react-on-rails-pro-node-renderer`
- [ ] CI `check-bundle-size` job passes on a fresh runner (no cached
`lib/`)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Refactor**
* Improved internal type annotations for file handling functionality. No
user-facing changes or functionality modifications.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

check-bundle-size CI fails on fresh runners due to pre-existing TS2769 error in node renderer prepare script

1 participant