fastify / fastify-funky

Make fastify functional! Plugin, adding support for fastify routes returning functional structures, such as Either, Task or plain parameterless function.
MIT License
74 stars 5 forks source link

RouteHandlerMethod override breaks TypeProviders #134

Open jabinb opened 1 year ago

jabinb commented 1 year ago

Prerequisites

Fastify version

4.12.0

Plugin version

3.0.0

Node.js version

16.14.2

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

22.04

Description

The RouteHandlerMethod override added in #50 omits the last three generic parameters (SchemaCompiler, TypeProvider and Logger) likely because it was made prior to https://github.com/fastify/fastify/pull/3398

This restricts the TypeProvider type to always be FastifyTypeProviderDefault resulting in all schema types being unknown

Steps to Reproduce

I've made a Typescript Playground where you can test out the issue.

Expected Behavior

The type provider declared by withTypeProvider should be used in the route handler.

kibertoad commented 1 year ago

thank you! could you send a pr for this?

jabinb commented 1 year ago

Yep, no worries, will submit one shortly.

jabinb commented 1 year ago

@kibertoad I've had a look at it, it seems like there's something deeper going on with the way the types are being merged as updating RouteHandlerMethod's signature to mirror upstreams still forces the type provider to be FastifyTypeProviderDefault.

You can see an example at this playground.

I think it may be because upstream RouteHandlerMethod is a type not an interface so you shouldn't be able to use an interface to merge with it, however in the playground example above the FunkyReply return type restriction still works :man_shrugging:

I'm not too familiar with fastify's type structure but maybe there's another target that can be used to restrict the handler return types?