Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 导出接口时出错_Javascript_Flowtype - Fatal编程技术网

Javascript 导出接口时出错

Javascript 导出接口时出错,javascript,flowtype,Javascript,Flowtype,如果我导入一个接口,流不会识别它,但是如果该接口是在同一个文件中声明的,它会按预期工作 工作示例: interface Action { execute(): Promise < any > ; } class CreateJuridicalPerson { constructor() {} static create() { return new CreateJuridicalPerson(); } } (new CreateJuridica

如果我导入一个接口,流不会识别它,但是如果该接口是在同一个文件中声明的,它会按预期工作

工作示例:

interface Action {
  execute(): Promise < any > ;
}

class CreateJuridicalPerson {
  constructor() {}



  static create() {
      return new CreateJuridicalPerson();
  }

}

(new CreateJuridicalPerson: Action);

//[flow] [flow] property `execute` of Action (Property not found in CreateJuridicalPerson)

您的代码无效,并引发以下错误

src/Action.js:7
  7: export default Action;
                    ^^^^^^ Action. type referenced from value position
  3: interface Action {
     ^ type Action
如果您正在使用核素,但没有看到错误,请尝试从命令行运行
流量检查。问题是类型和接口必须使用
导出类型
导出接口
导出,然后使用
导入类型

Action.js

// @flow

export interface Action {
  execute(): Promise<any>;
}

我的建议是避免模块之间的接口,您也可以使用类*接口是抽象的,因此不可导入*
src/Action.js:7
  7: export default Action;
                    ^^^^^^ Action. type referenced from value position
  3: interface Action {
     ^ type Action
// @flow

export interface Action {
  execute(): Promise<any>;
}
// @flow

import type { Action } from './Action'

class CreateJuridicalPerson {
  constructor() {}
  static create() {
    return new CreateJuridicalPerson()
  }
}

(new CreateJuridicalPerson: Action)

src/index.js:12
 12: (new CreateJuridicalPerson: Action)
                                 ^^^^^^ property `execute` of Action. Property not found in
 12: (new CreateJuridicalPerson: Action)
      ^^^^^^^^^^^^^^^^^^^^^^^^^ CreateJuridicalPerson