When I read an unknown variable, for example: req.bodyor JSON.parse(), and I know that it is formatted in a certain way, for example:
type MyDataType = {
key1: string,
key2: Array<SomeOtherComplexDataType>
};
how can i convert it, so the following works:
function fn(x: MyDataType) {}
function (req, res) {
res.send(
fn(req.body)
);
}
You can not tell me that:
req.body is mixed. This type is incompatible with object type MyDataType.
I guess this has something to do with Dynamic Type Tests , but figure out how ...
source
share