-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Removal of declaration merging #5061
Copy link
Copy link
Open
Labels
typescriptTypeScript relatedTypeScript related
Description
declaration merging is the technique we use in Fastify to decorate the types of our base objects. See https://github.com/fastify/fastify-static/blob/d40ce2d33481da7abcd261b1e8699ef31a9e2854/types/index.d.ts#L8-L17.
This technique has a major flaw: once a module is "seen" by TypeScript, those types are mergerd in original definition, even if the decorating plugin is not loaded in the current plugin tree.
After studying a bit of TypeScript, I think we can do better. In essence, we should be able to support something like:
import fp from 'fastify-plugin'
import { FastifyStaticMixin } from '@fastify/static'
export default fp(async function (app: FastifyInstance & FastifyStaticMixin, opts: object) {
})Or even better:
import fp from 'fastify-plugin'
import { FastifyStaticMixin } from '@fastify/static'
export default fp(async function (app: FastifyInstance & FastifyStaticMixin, opts: object) {
}, {
decorators: {
reply: FastifyStaticMixin
}
})Or some other analog syntax with native Fastify, e.g. withMixin<T>().
I think this would be a significant improvement on our TS story for v5. Wdyt?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
typescriptTypeScript relatedTypeScript related