是否可以在Flow中导入一个推断类型的对象?

时间:2017-04-26 15:51:26

标签: javascript flowtype

我可以在一个文件中包含以下对象

type MyType = { createdDate: Date }
export const myObject: MyType = { createdDate: new Date() }

我有兴趣在导入MyType时导入myObject

2 个答案:

答案 0 :(得分:3)

不必输出类型。

您可以通过以下方式推断出类型:

import typeof { MyType } from 'file';

答案 1 :(得分:0)

将您的type声明更改为以下内容:

export type MyType = { createdDate: Date }

然后,在任何其他文件中,您可以执行以下操作:

import type MyType from 'file'

'file'替换为您文件的实际位置。

Reference.

相关问题