facebook / facebook/flow

Classes treated as second class citizens

Open
#4,360 2 comments 0 reactions 0 assignees View on GitHub
Typing: destructors
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

With most of our operators, like $Keys, $ElementType. Classes are second class. They do not have indexable signatures which is a little off...

Why would this work:

```javascript
interface TestClass {
id: string
}

const fn = >(something: T, key: K, property: $ElementType): void => {
console.log(something, key, property)
}

let t = {id: 'goodbye'}
fn(t, 'id', 'hello')
```

But this not work:
```javascript
class TestClass {
id: string
}

const fn = >(something: T, key: K, property: $ElementType): void => {
console.log(something, key, property)
}

let t = new TestClass()
fn(t, 'id', 'hello')
```
Error:
```
Indexable signature not found in TestClass
```

This happens pretty consistently across the board with classes.
Classes should be treated as javascript objects across the majority of flow...

The only precise difference between a class and an object, new constructor && extra prototype definitions...

Please fix this.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.