Closed denchen closed 5 months ago
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.
@mcollina Let me first say that I'm far from an expert at Typescript, but I'm giving it a shot. My first few attempts at introducing generics didn't work at all, until I finally decided to introduce overloading similar to how the fastify()
types are overloaded here:
The overloading worked for at least my use case (for both default fastify and fastify with http2, but I'm not at all confident that it'll work for everyone else, nor am I sure if overloading is the only way to go about it. Thus far, I'm only modifying types/index.d.ts
and none of the actual code. I can still create a PR after I try to add a test or two, but it'll probably be a couple days from now.
modifying the types is ok. Also add a test for the type, we use tsd.
Closed by #65
Prerequisites
Fastify version
4.26.0
Plugin version
2.2.0
Node.js version
20.9.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
14.2.1
Description
Restartable doesn't seem to take a generic argument, so I'm wondering how to properly type an HTTP/2 server.
Steps to Reproduce
The following gives a TypeScript error:
http2
only exists onFastifyHttp2SecureOptions
, which extendsFastifyServerOptions
, but I don't see the proper way of tellingrestartable
that. If I create a helper function that instantiates the Fastify instance with the right types, I'll get a different (but related?) error:Expected Behavior
No response