#8062·flow

Error message when trying to call a class as a function is confusing

Author: k4b7Created Sep 5, 2019Updated Sep 6, 2025
Labelserror messagesdiscussion

The following code:

javascript
class Foo {};
const foo = Foo();

produces the following error message:

2: const foo = Foo();
               ^ Cannot call `Foo` because a call signature declaring the expected parameter / return type is missing in statics of `Foo` [1].
References:
1: class Foo {};
         ^ [1]

It would be clearer if error message stated that Foo is a constructor and must be called using new (or something to that effect).