我有一个使用 Flow 的普通 JavaScript 文件,如下所示:
// @flow
/*:: type orderType = number; */
let ot = 0 /*:: as orderType */;
但我收到错误
无效的类型转换语法。使用形式
而不是形式(<expr>: <type>)
。<expr> as <type>
但是,尝试该语法也会给我一个错误:
let ot = 0 /*:: : orderType */; // ■■■■ Unexpected token `:`, expected the token `;`
使用类型别名进行类型转换不适用于 Flow 中的注释类型吗?
正确的语法似乎是
let op /*: orderType*/ = 0;
假设您使用
number
而不是 Number
。