Reputation: 1145
I've a function which receives a class as a parameter :
myFunction = (Klass) => new Klass();
How do i specifiy Klass
parameter with flow ?
If i use Klass:SomeClass
, flow seems to be ok with that. But i was expecting this to give me an error since i thought :SomeClass
would indicate "an instance of SomeClass", which is not the case in my example (i'm passing the class itself)
What is the correct notation for this example ?
Edit:
As Aleksey pointed out in the comment, we can use the Class utility :
myFunction = (Klass:Class<SomeClass>) => new Klass();
Upvotes: 2
Views: 303
Reputation: 37938
To represent class type (constructor function) of an instance type you can use Class utility:
class SomeClass {}
const myFunction = (c: Class<SomeClass>) => new c();
Upvotes: 4