如何设置Flow类型声明 - lint up with error" not defined"?

时间:2017-03-23 16:49:38

标签: reactjs eslint flowtype

我刚开始使用键入的JS,目前只是导出/导入我的类型。在看了几件事之后,我认为正确的解决方案似乎是"声明"的想法。

阅读[https://flowtype.org/docs/declarations.html#pointing-your-project-to-declarations]后,我尝试了" .flowconfig" -style。

decls / types.js

private static void CheckDEP()
{
    var dep = SetProcessDEPPolicy(3);

    var handle = Process.GetCurrentProcess().Handle;
    var res = GetProcessDEPPolicy(handle, out var flags, out var permanent);
}

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool SetProcessDEPPolicy(uint dwFlags);

[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
static extern bool GetProcessDEPPolicy(IntPtr hProcess, out uint lpFlags, out bool lpPermanent);

然后我将declare type Post = { feed: Connection, } declare type Connection = { edges: Array<Edge>, pageInfo: PageInfo, } declare type Edge = { cursor: number, node: Node, } declare type PageInfo = { endCursor: number, hasNextPage: boolean, } declare type Node = { id: string, createdAt: number, } 目录添加到我的decls/ .flowconfig

.flowconfig

[libs]

然而,所有类型都没有定义错误,例如, &#39;连接&#39;没有定义。

我错过了什么吗?

1 个答案:

答案 0 :(得分:4)

由于您使用的是ESLint,因此需要添加eslint-plugin-flowtype扩展名并最低限度启用define-flow-type规则,以便ESLint不会将Flow类型标记为未定义。

ESLint配置:

{
  "plugins": [
    "flowtype"
  ],
  "rules": {
    "flowtype/define-flow-type": 2
  }
}