Hacker News new | ask | show | jobs
by leshow 3031 days ago
The difference IMO is that the interface is still a nominal declaration. With it you have a named type, while the alias is purely structural. in TS/Flow I prefer to use the type alias ubiquitously, however in other typed languages I prefer being more nominal. In Purescript, which supports both methods also, I almost always fully declare the type.
1 comments

TypeScript interfaces are purely structural. The effect on the type system of using `interface Foo { … }` vs `type Foo = { … }` is the same. I mean, the whole point of interfaces in TypeScript is that it's structural typing, and if you want nominal typing you use a class.

The only difference is readability and how tools like VSCode treat it (e.g. if you hover over something typed as an `interface`, VSCode just shows the interface name, though you can hold a modifier to see the whole definition).

All that said, if you want to exclusively use type aliases, you're certainly free to do so. But I expect most TypeScript developers will consider that to be a bit odd.