facebook / facebook/flow

Improve error message for undeclared class property initialization

Đang mở
#643 0 bình luận 2 reaction 0 người được giao Xem trên GitHub
error messages
Ngôn ngữ chính
Rust
Star
22.3k
Fork
1.9k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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."

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.