I created a specific interface called NewTransactionPayload to ensure that only objects of this type are accepted in the request body. Strangely, TypeScript does not show any errors when I host the application. Why is that?
// Sample interfaces
interface NewTransactionPayload {
transactionAmount: Number;
transactionDate: String;
transactionWallet: String;
transactionPocket: String;
transactionTag: String;
transactionDetails: String;
}
transactionsRouter.post('/api/transactions', (req, res)=>{
try {
const newTransaction:NewTransactionPayload = req.body;
// const newTransaction = req.body;
res.status(201).json(newTransaction);
} catch (err){
res.status(400).json({error: `Bad request. ${err}`})
}
});