如果我导入了一个接口,则流程无法识别它,但如果该接口在同一文件中声明,则它会按预期工作。
工作示例:
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)
失败的例子:
Action.js:
interface Action {
execute(): Promise < any > ;
}
export default Action;
CreateJurdicalPerson.js:
import Action from './Action'
class CreateJuridicalPerson {
constructor() {}
static create() {
return new CreateJuridicalPerson();
}
}
(new CreateJuridicalPerson: Action);
//quiet...
答案 0 :(得分:4)
您的代码无效并引发以下错误
src/Action.js:7
7: export default Action;
^^^^^^ Action. type referenced from value position
3: interface Action {
^ type Action
如果您使用的是Nuclide并且没有看到错误,请尝试从命令行运行flow check
。问题是必须使用export type
或export interface
导出类型和接口,然后使用import type
导入
Action.js
// @flow
export interface Action {
execute(): Promise<any>;
}
index.js
// @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