我无法弄清楚如何在两个文件中共享类型定义.考虑:
// /file_a.js
export const randomVariable: MySharedType = {thing: true};
// /file_b.js
export const anotherRandomVariable: MySharedType = {thing: false};
Run Code Online (Sandbox Code Playgroud)
两个文件都使用该MySharedType类型,因此我想将该类型声明移动到某些共享类型定义.
所以我为它创建了一个新目录,并在[libs]我的部分下指向它flowconfig.结果就是我有:
// in /flow/typeExtensions/SharedTypes.js
// @flow
export type MySharedType = {thing: boolean}
Run Code Online (Sandbox Code Playgroud)
但是,流程不想玩得好,仍然给我错误:
2: export const randomVariable: MySharedType = {thing: true}
^^^^^^^^^^^^ identifier `MySharedType`. Could not resolve name
Run Code Online (Sandbox Code Playgroud)
我找不到任何有关如何创建全局共享流类型定义的文档或示例.
这是一个小型回购,展示了这个问题:https://github.com/EvNaverniouk/shared-flow-types
请帮忙.
显然问题是Flow无法识别对global [lib]文件的更改.所以解决方案只是重启流服务器:
./node_modules/.bin/flow stop
./node_modules/.bin/flow start
现在共享类型工作正常.捂脸
| 归档时间: |
|
| 查看次数: |
844 次 |
| 最近记录: |