fastify / fastify-plugin

Plugin helper for Fastify
MIT License
197 stars 42 forks source link

fix inferring the correct fn type #218

Closed Uzlopak closed 1 year ago

Uzlopak commented 1 year ago

Fixes #217

I got help from @webstrand. Props to him.

It should now work.

According to webstrand

Typescript isn't currently capable of partial inference if you specify any of the type parameters, the rest get filled in with their defaults this is why you see some typescript-specific apis doing stuff like foo()("blah") because the first function call doesn't perform any inference, but typescript lets the second function call infer from its parameters

Maybe needs a new paragraph regarding typing in the readme.md were we basically write, that they should not use the generics but specify the types on the parameters, when calling fastifyPlugin?

Checklist

Uzlopak commented 1 year ago

hmm. i think it is false green. Dont merge

Uzlopak commented 1 year ago

@fastify/typescript

Can you have a look please?

I am actually highly confident, that this is the solution.

fox1t commented 1 year ago

Hey. This approach is new to me: instead of using polymorphism, we are going with a generic inference. I like it! I am wondering if there are other points in the Fastify ecosystem where we can use the same approach (the same one we did with the infamous triplet and the export = thing when we discovered it)

mcollina commented 1 year ago

How? Could you open a fresh issue?

Uzlopak commented 1 year ago

@mcollina Probably mixed use of async and callback. like we had in #220 Should we add the infomation, that you should not mix both approaches?

mcollina commented 1 year ago

Should we add the infomation, that you should not mix both approaches?

yes

Uzlopak commented 1 year ago

created an issue #221