foal
foal copied to clipboard
add: optional typed request
Issue
Closes #1269
Solution and steps
This exposes a custom request object and extends Foal's request object, thus allowing you to manually type your request params and body, to make typescript happy. Makes working with validation easier.
This works, but a better solution would just be to make ValidatePathParam and ValidateBody automatically type ctx
.
Please let me know if this makes sense and I can add some docs.
Example Usage
@Get()
@ValidatePathParam('versionId', { type: 'string', format: 'uuid' })
async getDocumentVersionApprovers(ctx: Context<UserContext, object, Request<undefined, {versionId: string}>>) {
const {
request: {
params: { versionId },
},
user,
} = ctx;
Checklist
- [ ] Add/update/check docs (code comments and docs/ folder).
- [x] Add/update/check tests.
- [x] Update/check the cli generators.