facebook / facebook/flow

Improve error message for undeclared class property initialization

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

描述

Flow requires that class properties be declared before they can be initialized in a constructor. This behavior is reasonable, but the error message should guide the user to the solution:

``` javascript
/* @flow */

class Foo {
constructor() {
this.bar = "baz";
}
}
```

```
test.js|5 col 5 error| assignment of property bar
|| Property not found in
test.js|3 col 7 error| Foo
||
```

A better error message would direct the user to declare the type of `bar`, as follows:

``` javascript
/* @flow */

class Foo {
bar: string;
constructor() {
this.bar = "baz";
}
}
```

```
|| No errors!
```

A better message might be "Property must be declared in class."

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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