Flow的文档说:When you create an object without any properties, you create an unsealed object type in Flow.是否有可能创建一个没有属性的密封对象?
我的用例如下.我想初始化state为一个空对象,并给状态以下类型:
type EmployeesViewState = {|
employeesRequest?: Request<Array<Employee>>,
geosRequest?: Request<Array<Geo>>,
|};
Run Code Online (Sandbox Code Playgroud)
我尝试分配空对象时得到的错误是
33: state: EmployeesViewState = {};
^^ object literal. Inexact type is incompatible with exact type
33: state: EmployeesViewState = {};
^^^^^^^^^^^^^^^^^^ exact type: object type
Run Code Online (Sandbox Code Playgroud)
当然,由于我还没有提供请求,我无法分配它们.我也无法分配undefined给对象,因为状态是用管道定义的,即它是一个确切的类型.
我可以通过说法来欺骗流程,const a: any = {}; state = a;但这看起来真的很笨拙.还有其他方法可以解决这个问题吗?
flowtype ×1