DEV Community

Discussion on: Flow 0.99: Callable Properties, Function Statics, and More

 
yawaramin profile image
Yawar Amin

Oh I see what you mean now–and why the interface type works! Because an object with type:

interface Common {
  a: number,
  b: string,
}

... can always be safely downcast to its subtype type HasExtra = Common & {c?: string}. In fact now I'm surprised the type version doesn't work, ha ha. In any case, yeah I recommend to looking at interfaces more heavily. The doc page doesn't mention this but they can be used to model the shapes of not just classes but also 'POJOs', just like in TypeScript. This gives them quite a wide variety of use cases.

Thread Thread
 
wgao19 profile image
Wei Gao

So, it turns out that (from my understanding) interfaces allow structural subtyping which distincts themselves from types.

Although, I run into this error that I don't quite understand, but looks interesting..

Thread Thread
 
yawaramin profile image
Yawar Amin

Wow, yeah that's a head-scratcher. No idea what's happening there!