Class-returning-function breaks nominal typing of instances
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Flow currently returns the same nominal type for functions returning fresh classes, e.g.
```js
function create() {
return class K {};
}
let K1 = create();
(create(): Class); // NG, but Flow yields a false positive
```
I currently have a memoizing polymorphic function that depends on this behavior, i.e.
```js
export class PointerList {
static _specials: { [hash: string]: Class> };
static of | BoolList>(_R: Class): Class> {
const hash = _R._hash();
const cached = this._specials[hash];
if (cached) {
return ((cached: any): Class>);
}
class List extends ByteAlignedList {
static _hash(): string {
return "L("+_R._hash()+")";
}
// ...
}
return this._specials[hash] = List;
}
}
```
Can I rely on this pattern?
Contributor guide
Assessment
This issue has not been assessed yet.