LoginSignup
1
0

More than 5 years have passed since last update.

Flow の autocomplete で import type した型が not enough type information to autocomplete となってしまうときの対処法

Posted at

状況

Flowtype の autocomplete 機能で、外部ファイルで export type した型を import type しても型の情報が取得できず、Error: not enough type information to autocomplete となってしまう。

最小構成

.
├── .flowconfig
├── package.json
└── src
    ├── lib
    │   └── index.js
    └── types
        └── index.js
.flowconfig
[ignore]

[include]

[libs]

[lints]

[options]
package.json
{
  "devDependencies": {
    "flow-bin": "^0.56.0"
  }
}
src/lib/index.js
// @flow

import type { T } from '../types'

const t: T = {
  num: 1,
}

t.
src/types/index.js
// @flow

export type T = {
  num: number,
}

再現手順

$ node_modules/.bin/flow autocomplete 9 3 < src/lib/index.js
Error: not enough type information to autocomplete

対処法

型を export しているファイルが import しているファイルと同階層にない場合、flow autocomplete の引数に、標準入力に加えてファイルパスを渡す必要があった。

$ node_modules/.bin/flow autocomplete src/lib/index.js 9 3 < src/lib/index.js
hasOwnProperty (prop: any) => boolean
isPrototypeOf (o: any) => boolean
num number
propertyIsEnumerable (prop: any) => boolean
toLocaleString () => string
toString () => string
valueOf () => Object

余談: なぜハマったのか

Vim の補完補助プラグインの 1 つである deoplete から flow を使おうとしていて、これを実現するプラグインがあった。

この 2 つのプラグインを試していたが、これらは flow autocomplete の引数にファイルパスを渡しておらず、上記の挙動により import type した型の補完が効かなくなっていた。
deoplete-flow は既にこの問題を修正する Pull Request が投げられている (steelsojka/deoplete-flow#9) ので、この Pull Request が merge されるまでは Fork 先のブランチを利用すると良いだろう。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0