The interface
and type
declarations seems to do the same thing. When do you use one over the other?
type Fooable = { foo(): string }
vs
interface Fooable { foo(): string }
// One major difference between type aliases vs interfaces are that interfaces are open and type aliases are closed. This means you can extend an interface by declaring it a second time. // In the other case a type cannot be changed outside of its declaration.
Type aliases provide alternative names for existing types. If the type name is too long you can introduce a different shorter name and use the new one instead. It's useful to shorten long generic types.
User Interface Flows show graphically how a user will navigate a solution's user interface.
A type alias is basically a name for any type. Type aliases can be used to represent not only primitives but also object types, union types, tuples and intersections.
This is a great question. Ideally there would be no difference between an interface and an object type. As implemented, there are a handful of (often subtle) differences between them.
The biggest difference is that Flow considers methods declared on an interface to be "read-only." This allows subtypes to be covariant w.r.t. methods, which is a very common pattern with inheritance hierarchies.
In time, I would like to see Flow unify these concepts, but until then here's my rule of thumb for choosing between interfaces and object types:
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With