We have a backend API which expects below type in the request body.
type taskslistrequest = {
clientgroupcode: string[];
startindex: number;
pagesize: number;
}
This is how I am parsing the request body:
const tasklistreq: taskslistrequest = req.body.taskslistrequest as taskslistrequest;
However, typescript doesn’t throw any error if I send below request body from postman.
{
"taskslistrequest": {
"clientgroupcode": [
"AAB",
"AAC",
"AAD"
],
"startindex": "0",
"pagesize": "50"
}
}
Can you please help me to understand how can I make sure that if there is any type mismatch then it is captured while parsing the request body itself.
I am using:
- Typescript – 5.3.3
- NodeJS – 20.10.0
- Express – 4.18.2