FoalTS / foal

Full-featured Node.js framework, with no complexity. 🚀 Simple and easy to use, TypeScript-based and well-documented.
https://foalts.org/
MIT License
1.88k stars 137 forks source link

Make A Controller's Request Typed #1269

Open ConorCorp opened 2 weeks ago

ConorCorp commented 2 weeks ago

Hi there, would love to have all my request params/body/etc. I already define them in ValidatePathParam and ValidateBody, so I know that they will be the correct types.

Ideally, this would happen automatically and ValidatePathParam would just pass the correct types into ctx's request object.

export class ApproverController {
  @Get()
  @ValidatePathParam('versionId', { type: 'string', format: 'uuid' })
  async getDocumentVersionApprovers(ctx: Context) {
      const {
      request: {
        params: { versionId }, // <----- This is an "any", and it should be a string
      },
      user,
    } = ctx;
}
}
ConorCorp commented 2 weeks ago

Here's a patch package in the meantime with an identical solution to the linked PR.

@foal+core+4.4.0.patch

ConorCorp commented 5 days ago

I added another patch package here which also adds typing to the query params.

I didn't put it in the PR as I haven't heard back anything yet. Can add it in though if there's movement.