Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module augmentation #471

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

nemanja-tosic
Copy link

WIP #5093

Checklist

expectType<FastifyPluginAsync<FastifyStaticOptions, Server>>(
fastifyStaticStar.fastifyStatic
)
app.register(fastifyStatic, { root: '/' })

Choose a reason for hiding this comment

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

If I properly understand the change, we now require an object to be always passed when we register a fastify plugin (so it's no longer optional). This is a breaking change, we should really careful if we want to ship it as it is, since it will break existing TS codebases

Copy link
Author

@nemanja-tosic nemanja-tosic Nov 29, 2024

Choose a reason for hiding this comment

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

An object is not necessary, fastify static plugin has a mandatory root param. Removing the object leads to

  Overload 1 of 3, (plugin: FastifyPluginCallback<FastifyPluginOptions, BaseFastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault, FastifyDecorators>>, opts?: FastifyRegisterOptions<...> | undefined): BaseFastifyInstance<...> & ... 1 more ... & { ...; }, gave the following error.
    Argument of type FastifyStaticPlugin<BaseFastifyInstance<any, any, any, any, any, FastifyDecorators>> is not assignable to parameter of type FastifyPluginCallback<FastifyPluginOptions, BaseFastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault, FastifyDecorators>>.
      Types of parameters opts and opts are incompatible.
        Property root is missing in type FastifyPluginOptions but required in type FastifyStaticOptions.
...

Making root optional fixes the error.

If anything, the possibility of not providing root was a bug as far as i can tell.

@@ -129,20 +138,24 @@ const appWithHttp2 = fastify({ http2: true })

appWithHttp2
.register(fastifyStatic, options)
.after(() => {
appWithHttp2.get('/', (request, reply) => {
.after((err, instance) => {

Choose a reason for hiding this comment

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

This is a breaking change since we no longer support the scenario of the test: if err and instance params are not defined, .sendFile will not exist at TS level
image

Copy link
Author

Choose a reason for hiding this comment

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

I do not see which test case this is, the code is obscured with the error message. Can you provide a test case that i can take a look at?

Choose a reason for hiding this comment

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

It refers to the test case on line 140.
Basically, with the change, this test should still pass

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.

2 participants