4
当我读到一个未知的变量,例如:req.body
或JSON.parse()
,并知道它是在一个特定的方式格式化,例如:如何混合型转换为对象的类型
type MyDataType = {
key1: string,
key2: Array<SomeOtherComplexDataType>
};
我怎么能转换它,所以,下面的工作:
function fn(x: MyDataType) {}
function (req, res) {
res.send(
fn(req.body)
);
}
它一直没有告诉我说: req.body is mixed. This type is incompatible with object type MyDataType
。
我认为这事做与Dynamic Type Tests但弄清楚如何...