Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses TypeScript compilation issues when using Fastify with the exactOptionalPropertyTypes compiler option. It introduces a minimal type interface for the setupFastifyErrorHandler function to avoid type matching problems with Fastify's complex overloaded methods.
Key Changes:
- Introduced
FastifyMinimaltype that defines only theregistermethod needed bysetupFastifyErrorHandler - Updated
setupFastifyErrorHandlerto acceptFastifyMinimalinstead ofFastifyInstance
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/node/src/integrations/tracing/fastify/types.ts | Adds the new FastifyMinimal type with minimal surface area to avoid exactOptionalPropertyTypes issues |
| packages/node/src/integrations/tracing/fastify/index.ts | Updates setupFastifyErrorHandler parameter type from FastifyInstance to FastifyMinimal to use the relaxed type |
The implementation is sound and well-documented. The new FastifyMinimal type uses structural typing with permissive any types to ensure compatibility with Fastify v3-v5, and the type variance analysis confirms the signature is compatible with actual Fastify instances. No issues were found in this review.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
When using exactOptionalPropertyTypes, it is pretty hard to match Fastify's instance types given all the missing overloads from the partial signature we have. The problematic area is around
addHook.We either need to have all the signatures implemented exactly, or outright import Fastify's types which is not ideal since it is not a dependency.
I opted to relax the types specifically for
setupFastifyErrorHandlerby providing a minimal instance with the one method it needs to avoid TS trying to matching the other properties and methods signatures, not ideal but simple enough.I verified that this works for Fastify v3 throughout v5
closes #18619