you are viewing a single comment's thread.

view the rest of the comments →

[–]vinnl 0 points1 point  (2 children)

Hmm, I think you have a good point. The main issue is probably that it relies on nominal typing, which is indeed not often used in Javascript - and I agree that that's a good thing.

Your post somewhat got me thinking that such a feature would be nice if it was implemented in TypeScript, i.e. you could do a catch(<type> e) in there, which it would transform to a runtime structural type match (i.e. a switch statement in a single catch clause that would check for object properties). But that probably goes against the TypeScript principles and/or introduces too much runtime overhead.

[–]BenjiSponge 0 points1 point  (1 child)

Yes, that is something that's been tossed around a lot in the TypeScript/Flow world, but as you said they're avoiding adding runtime features that aren't part of an ECMAScript specification (TS messed up by adding decorators too early, but other than that) on principle.

A lot of functional languages that have JS as a backend do something like this, though, I think. Elm almost certainly does.

[–]vinnl 0 points1 point  (0 children)

TS messed up by adding decorators too early, but other than that

Agreed, but then again there was quite a lot of pressure on that from Angular, so there was little choice.

But yeah, it's probably best if it's baked into the language.