News for hackers. Stuff that matters.
Re:Typescript: class vs. interface by leshow on Tuesday February 27, 2018 @01:01PM (#16476072)
If you want to be purely structural, why even use an interface? You can just as easily write:

type MyType = { a: number, b: string };

Re:Typescript: class vs. interface by eridius on Tuesday February 27, 2018 @01:50PM (#16476572)
That's basically the same thing as using an interface. An interface is just a more formal way of declaring it.
Re:Typescript: class vs. interface by leshow on Friday March 02, 2018 @03:48PM (#16505548)
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.
Re:Typescript: class vs. interface by eridius on Friday March 02, 2018 @05:26PM (#16506334)
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.

Re:Typescript: class vs. interface by dvlsg on Tuesday February 27, 2018 @04:07PM (#16477890)
It affects things like previews / mouse hovers in editors like vscode, too. Interfaces will show the interface name, types will show the structure.
Re:Typescript: class vs. interface by eridius on Tuesday February 27, 2018 @04:48PM (#16478281)
In VSCode if you want to see the structure of an interface, hold command (on macOS; not sure about windows/linux) while hovering.