facebook / facebook/flow

Classes treated as second class citizens

Aperta
#4,360 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Typing: destructors
Lingua principale
Rust
Stelle
22.3k
Fork
1.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.