SkeLLLa / fastify-metrics

Prometheus metrics exporter for Fastify
https://savelife.in.ua/en/donate-en/
MIT License
99 stars 33 forks source link

[bug] new routeConfig types break route config for other plugins #64

Closed tandpfun closed 2 years ago

tandpfun commented 2 years ago

Hey hi!

After updating to v7.4.0, I ran into some issues with my other config options. It appears that the update doesn't let any other plugins or custom config options be entered other than the ones for this plugin.

CleanShot 2022-09-30 at 20 16 54@2x

I haven't fully figured out the issue, but it looks like something with the overwriting of the context config? The @fastify/rate-limit plugin I'm using doesn't implement any types, and config should still work for any config, even ones without types defined.

Package version things: @fastify/rate-limit: 7.4.0 fastify: 4.7.0 fastify-metrics: 9.2.2

Thank you!

Benricheson101 commented 2 years ago

Fastify's FastifyContextConfig appears to default to an empty interface {} type. TypeScript treats {} as a generic Object type -- you can assign any object to this type (in JS that's pretty much everything...string, number, {a: 1}, etc). When fastify-metrics extended the type, it made it from {} into a proper interface, so normal interface rules apply.

TS playground example

SkeLLLa commented 2 years ago

Since fastify rate-limiter doesn't extend the type FastifyContextConfig you should either submit a PR to rate-limiter types or you should extend it manually. fastify-metrics has no relation to it, it only extends FastifyContextConfig.

How to do this you can see in https://github.com/SkeLLLa/fastify-metrics/blob/master/src/index.ts#L23, for example.