Re:Tricks I wish I knew when I learned TypeScript
by arenaninja on Tuesday October 12, 2021 @10:38AM
(#28840244)
Yes the error reporting is why I prefer interfaces over types since a long time now. The definition is useless in many cases
- in error reporting: type aliases may be replaced by their definition in error reporting.
- you cannot create union types with interfaces
- legacy versions of TypeScript does not enable to create recursive type aliases such as type `List<V> = {v: V, right: List<V> | undefined }`
- interfaces with same name are merged
However the frontier between type aliases and interfaces seems more and more blur. Generally interfaces are encouraged over type aliases. I personally prefer type aliases because there are more capable and seems more elegant to me. However their poor support in error reporting makes me rely more on interfaces when possible.