Skip to content
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

types: improve typing to allow custom request and reply #211

Merged
merged 1 commit into from
Feb 11, 2024

Conversation

Puppo
Copy link
Contributor

@Puppo Puppo commented Jan 11, 2024

This PR closes #207

Checklist

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Comment on lines +15 to +16
Request extends FastifyRequest = FastifyRequest,
Reply extends FastifyReply = FastifyReply
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, looks not correct. Why is Request and Reply not depending on the Generic Types from FastifyInstance?

Suggested change
Request extends FastifyRequest = FastifyRequest,
Reply extends FastifyReply = FastifyReply
Request extends FastifyRequest = Request extends FastifyRequest = FastifyRequest<RawServerDefault, RawRequest, FastifySchema, TypeProvider, ContextConfigDefault, Logger>,
Reply extends FastifyReply = FastifyReply<RawServer, RawRequest, RawReply, RouteGenericInterface, ContextConfigDefault, FastifySchema, TypeProvider>

Untested but I would expect this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FastifyRequest and FastifyReply interfaces have changed from your example.
The default should be equal to the old value to prevent breaking the previous code.
Furthermore, now the FastifyRequest accepts other generic types, for instance, RouteGeneric, and in this way, the users can pass the request as they prefer.
If you take a look at the tests, I tried to break nothing and include your request to leave the power to the user to choose the request type.

Copy link
Contributor

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check my comment.

@Puppo Puppo requested a review from Uzlopak January 12, 2024 08:23
@hershmire
Copy link

@Puppo thanks for the PR!

@mcollina @Uzlopak any resolution on this?

@Puppo
Copy link
Contributor Author

Puppo commented Feb 2, 2024

@Uzlopak any news on this one? otherwise Matteo cannot merge the PR.

@Uzlopak
Copy link
Contributor

Uzlopak commented Feb 2, 2024

@fastify/typescript

Can somebody else have a look at it. I dont want to be a blocker, but I dont think that the arguments are valid as the generic types are not passed down to the FastifyReply and FastifyRequest.

@Uzlopak Uzlopak dismissed their stale review February 2, 2024 16:48

I dont want to block, but I am not convinced either.

@Uzlopak Uzlopak requested a review from climba03003 February 2, 2024 16:48
@climba03003
Copy link
Member

I dont think that the arguments are valid as the generic types are not passed down to the FastifyReply and FastifyRequest.

That is true, but most of the time people use only the default server then it would be fine.
It worth a trial how it impact.

@Uzlopak
Copy link
Contributor

Uzlopak commented Feb 8, 2024

@mcollina

Somebody has to decide if this gets merged and published or not.

@mcollina mcollina merged commit 1d6bb44 into fastify:master Feb 11, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to use a Typescript generic for the Params property off of the request
5 participants