【问题标题】:How can I export a flow interfaces using CommonJS?如何使用 CommonJS 导出流接口?
【发布时间】:2019-04-02 10:59:16
【问题描述】:

我不确定我的构建是否良好,但在我的package.json 中,我有

"scripts": {
    "build": "flow-remove-types src/ -d build/",

我有一个types/sentence.js,它有:

// @flow

type SentenceObject = {
  foo: number,
  bar: boolean,
  baz: string,
};

module.exports = {
  SentenceObject
};

在我的库文件中,我有:

const { SentenceObject } = require('../interfaces/sentence');

问题,当我yarn build 是:

src/interfaces/sentence.js
 ↳ Syntax Error: Unexpected token, expected = (3:27)
   2:  export type SentenceObject {

我做错了什么?

【问题讨论】:

    标签: flowtype


    【解决方案1】:

    好像有no CommonJS style for require flow types。相反,您可以使用export/importas suggested in docs。所以在你的情况下,它可能是这样的:

    types/sentence.js:

    // @flow
    export type SentenceObject = {
      foo: number,
      bar: boolean,
      baz: string,
    };
    

    注意export 关键字。

    在你的库文件中你可以使用import type {...} from '':

    import type { SentenceObject } from '../interfaces/sentence';
    

    【讨论】:

      猜你喜欢
      • 2018-07-02
      • 2019-09-23
      • 1970-01-01
      • 2018-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-12
      • 2016-06-28
      相关资源
      最近更新 更多