facebook / facebook/flow

`typeof A` vs `Class<A>`

Open
#1,652 2 comments 0 reactions 0 assignees View on GitHub
Needs docs
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Ran into this one a little bit ago while working on a Bluebird lib:

According to the documentation:

> Given a type T representing instances of a class C, the type Class is the type of the class C.

So it would stand to reason that a definition like this should work:

``` js
declare module 'bluebird' {
class BluebirdPromise {
// ....
}
declare var exports: Class;
}
```

Yet this throws all kinds of errors about polymorphic types not equaling class types.

The solution is to export:

``` js
declare var exports: typeof BluebirdPromise;
```

When should one use `Class` vs `typeof`?

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.