types!: remove declaration-merging reliance with registration-scoped decorator typing#6581
types!: remove declaration-merging reliance with registration-scoped decorator typing#6581
Conversation
9353305 to
870aff4
Compare
docs/Reference/Logging.md
Outdated
There was a problem hiding this comment.
> [Pino documentation](https://getpino.io/#/docs/api?id=opt-serializers) for more
This line needs to be modified, otherwise the CI will fail with the error "Fragment not found"
There was a problem hiding this comment.
Fixed in 3448dc9 by switching this to the current Pino docs anchor.
There was a problem hiding this comment.
Rebased the branch onto current main; the fix is now on top in 4e16eb9b/759868e7.
docs/Reference/TypeScript.md
Outdated
There was a problem hiding this comment.
Fastify uses [Pino](https://getpino.io/#/) logging library under the hood. Since
idem here, this line needs to be modified, otherwise the CI will fail with the error "Fragment not found"
There was a problem hiding this comment.
Fixed in 3448dc9 by using the canonical getpino.io URL without the broken fragment.
There was a problem hiding this comment.
Rebased the branch onto current main; the fix is now on top in 4e16eb9b/759868e7.
1169710 to
759868e
Compare
|
Fixed the two broken Pino links and rebased the branch onto current Local checks run successfully:
|
| request: FastifyRequest<RouteGeneric, RawServer, RawRequest, NoInfer<SchemaCompiler>, TypeProvider, ContextConfig, Logger, Decorators>, | ||
| reply: FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Decorators> |
There was a problem hiding this comment.
This looks like the wrong decorator generic is being passed into route-level errorHandler. request and reply should receive Decorators['request'] and Decorators['reply'] no?
|
This is a regression test from my review that currently fails but should pass: import fastify from '../../fastify'
import { expectType } from 'tsd'
const app = fastify()
.decorate('svc', { ok: true })
.decorateRequest('user')
.decorateReply('sendOk', function () {
return this.send({ ok: true })
})
app.addHook('preHandler', function (req, reply, done) {
expectType<boolean>(this.svc.ok)
expectType<void>(req.user)
reply.sendOk()
done()
})
app.get('/', {
errorHandler (error, req, reply) {
expectType<boolean>(this.svc.ok)
expectType<void>(req.user)
reply.sendOk()
reply.send({ ok: true })
}
}, async function handler (req, reply) {
expectType<boolean>(this.svc.ok)
expectType<void>(req.user)
reply.sendOk()
}) |
Summary
This PR removes reliance on global declaration-merging assumptions for Fastify decorator typing and moves to a registration-scoped model where type visibility follows encapsulation and
register()flow.It includes:
decorate(),decorateRequest(),decorateReply()andregister()carry decorator effects through instance types;docs/Guides/Migration-Guide-Declaration-Merging.md.Context / previous attempts
This work incorporates lessons from prior attempts and follow-ups discussed in:
and provides a consolidated migration path plus updated docs.
Breaking change
This is a semver-major TypeScript change:
Runtime encapsulation behavior is unchanged; this is a type-transport correctness change.
Validation
npm run test:typescript✅npm run lint:markdown -- docs/Guides/Migration-Guide-Declaration-Merging.md docs/Guides/Index.md docs/Reference/TypeScript.md docs/Reference/Hooks.md✅Issue
Closes #5061.