I'm struggling to understand the "correct" way to handle types in Hapi with @types/hapi.
A minimal example:
server.route({
method: 'POST',
path: '/example',
options: {
pre: [{
assign: 'example',
method: (req) => {
return { msg: `Mr. ${req.payload.name} Example` };
},
}],
},
handler: (req) => {
return {
success: true,
info: req.pre.example.msg,
};
},
});
My question is simply how do I get across the correct typings for req.payload
and req.pre
?
I can cheat the payload with type assertion but that seems unideal. I can't seem to even do that for pre. I'll just get Property '[key]' does not exist on type 'object'.
.
For what it's worth I'm using io-ts to validate the payload in my actual code, but validation appears to make no difference to the types.
Help appreciated, cheers!