facebook / facebook/flow

The `throw` operator should be more strict

未关闭
#2,172 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
linter
主要语言
Rust
星标
22.3k
派生
1.9k
PR 合并指标
30 天内没有已合并 PR

描述

I tried searching, but I didn't find any existing issues about this.

Currently, using version 0.30.0 of flow-bin, the following code shows no errors:

```
function foo() {
throw null;
}

function bar() {
throw 5;
}

function qux() {
throw [];
}
```

It seems that the `throw` operator will accept any type.

I think it should only accept `Error`. If that is too restrictive, it could be relaxed to `Error | string`.

This actually bit me when I was writing a function which accepts an optional argument: if the argument is not provided, then it will `throw` `undefined`, which is not what I wanted.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。