Re:TypeScript at Slack
by Rapzid on Tuesday April 11, 2017 @10:25PM
(#14094245)
I'll go out on a limb though and posit that classes are now idiomatic JS when doing OO. Shops are not cutting modern JS with objects built up via direct prototype manipulation.
[ Parent
| on HN ]
Re:TypeScript at Slack
by charlieflowers on Wednesday April 12, 2017 @01:29AM
(#14095017)
Dunno, but I hope not. We built a moderate-sized TS codebase with _no objects at all_. Just functions and data types. Roughly functional ... with the caveat that nothing was preventing us from mutating incoming params (though our intent was not to do so).
I'd like to hope many people are using TS in a functional style.
EDIT -- there was one object ... we had to create an exception class for some reason ... don't fully recall the details.
It's a bit wordy, but I think you can do something like:
function test ({param1, param2}: {readonly param1: string, readonly param2: number}) {
return
}A codebase with no objects... I am guessing you mean no classes.
Seeing how functions are objects in JavaScript and all...
Re:TypeScript at Slack
by charlieflowers on Wednesday April 12, 2017 @08:34PM
(#14103028)
:rollseyes:
Agreed. ES6 class syntax is superior to constructor functions and prototype mutation, because it's declarative and statically analysable.
I think the only legitimate reason left not to use ES6 class syntax is (for perf sensitive code) performance, but that's a negligible and temporary problem as the JS engines will fix that over the next 6 months.