4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

flow 0.63でsetTimeoutとsetIntervalでエラーが起きる場合

Last updated at Posted at 2018-01-09

型定義が更新されて戻り値をnumberにしている場合型エラー起きます。

const hoge: number = setTimeout(() => {}, 300)

Try Flow | Flow

TimeoutIDIntervalIDがGlobalで定義されているのでそれを使うように更新します

const foo: TimeoutID = setTimeout(() => {}, 300);
const bar: IntervalID = setInterval(() => {}, 300);

まあ、普通に推論でいいと思います。自分の場合はMapのキーとして使っていたのでnumberからの変更が必要でした。

const foo = setTimeout(() => {}, 300);

雑記

この変更のおかげで、clearIntervalclearTimeoutと間違えて使っているのに型レベルで気づけました。opaque type便利です。

参照

0.63.x regression: setTimeout() & setInterval() return types broken · Issue #5627 · facebook/flow

4
5
1

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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?