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
fix: propagate generics from FastifyRegister to plugin type #4034
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you include a tsd test as well?
@RafaelGSS Yep, will do when I have time. |
Fixed commit message. |
Changing back to a draft - there's a failing test. |
The failing test is in
The problem is to do with passing anonymous (and therefore implicitly typed) plugin into |
The above issue was resolved by providing default values inferred from the instance on which |
Moved tests into the relevant file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
cc: @sinclairzx81 |
@climba03003 @fox1t can you take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am only afraid will it affect the non-default generic.
For example, people using http2
or https
.
@sinclairzx81 do you approve this? |
@mcollina Hi, this looks ok to me. As suggested by @climba03003, it may be good to put some TS tests up around the But other than that, this looks great :) @stefee Nice work! |
@climba03003 @sinclairzx81 @mcollina Which type signature is expected for a https server instance? default:
http2:
with type provider:
https: ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@stefee The following generic arguments should match each of the varying server types. import * as http from 'http'
import * as https from 'https'
import * as http2 from 'http2'
...
// With Http
const serverWithHttp = fastify({ })
type ServerWithHttp = FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse>
...
// With Https
const serverWithHttps = fastify({ https: { } })
type ServerWithHttps = FastifyInstance<https.Server, http.IncomingMessage, http.ServerResponse>
...
// With Http2
const serverWithHttp2 = fastify({ http2: true })
type ServerWithHttp2 = FastifyInstance<http2.Http2Server, http2.Http2ServerRequest, http2.Http2ServerResponse>
... Have tested the HTTPS variant locally, and all looks good to me :) Good work! |
LGTM! Nice job! |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Closes #4032
Checklist
npm run test
andnpm run benchmark
and the Code of conduct