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但弄清楚如何...