首页 > 解决方案 > 从文件夹索引中的多个文件重新导出流命名接口导出

问题描述

我有一个interfaces文件夹,其中包含一个或多个 Flow 接口的不同文件。

我想从一个index.js文件中导出我的所有接口,如下所示:

interfaces/index.js

/* @flow */

import type config from './config'

export default {
  ...config,
}

但 Flow 不会让我返回此错误:

Cannot reference type config [1] from a value position.Flow(InferError)

interfaces/config.js

/* @flow */

export interface Config {
  smtp: {
    host: string,
    secure: boolean,
    port: number,
    auth: {
      user: string,
      pass: string,
    },
    tls: {
      rejectUnauthorized: boolean,
    },
  },
  company: Company,
}

export interface Company {
  name: string,
  phone: string,
  address: string,
  product: {
    name: string,
  },
}

有没有办法做到这一点?提前致谢

标签: javascriptflowtype

解决方案


终于找到了解决办法,我需要用到的export type { ... } from '...'语法,如下:

interfaces/index.js

/* @flow */

export type * from './config'

希望这对其他人有用:)


推荐阅读