Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Refactor backend controllers to be typed as RequestHandler #7

Closed
LoneRifle opened this issue Aug 3, 2021 · 0 comments
Closed

Refactor backend controllers to be typed as RequestHandler #7

LoneRifle opened this issue Aug 3, 2021 · 0 comments
Assignees

Comments

@LoneRifle
Copy link
Contributor

LoneRifle commented Aug 3, 2021

Some of the backend controllers are typed incorrectly. express middleware functions should be typed as RequestHandler (can import from ‘express’) and one should always supply generic type arguments to specify the shape of the route params, response body, request body and query params.

Rationale

If you go to getSingleAgency and try to access req.body.nonsense, req.query.nonsense or req.params.nonsense, you can see that they are all either any or string, even though we know that these are undefined. this is because there are no generic type arguments to Request and Response, so everything defaults to any or string.

Example

https://github.com/opengovsg/FormSG/blob/f4db38bde03c59ec0b8856bfed08f0f31bdcb538/src/app/modules/submission/email-submission/email-submission.controller.ts#L34-L38

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants