News for hackers. Stuff that matters.
Re:TypeScript Is Surprisingly OK for Compilers by flohofwoe on Friday August 18, 2023 @05:32AM (#37173235)
"Modern" Javascript essentially is Typescript without the type hints (e.g. if you ignore the historical baggage, JS is actually a fairly decent language).
Re:TypeScript Is Surprisingly OK for Compilers by junon on Friday August 18, 2023 @05:50AM (#37173395)
I actually argue JS was a better language before all of the changes made, starting with const/let. The only thing I'd say makes sense are classes but the fact they aren't syntax sugar over prototypes was a mistake.

People wanted a different language, they should have gotten more scripting languages in the browser. Not changing JavaScript so much that it's no longer JavaScript.

Re:TypeScript Is Surprisingly OK for Compilers by flohofwoe on Friday August 18, 2023 @05:57AM (#37173456)
Coming into web development fairly recently (after 2013 or so) from the statically typed hemisphere and without closely following the Javascript history from the start I naturally cannot agree ;)

(things like the scoping rules for 'var' is just bizarre, same with the concept of 'prototypes')

Looking at typical "old-school" Javascript code gives me the creeps the same way as looking at K&R C code ;)

Re:TypeScript Is Surprisingly OK for Compilers by shrimpx on Friday August 18, 2023 @06:16AM (#37173617)
> aren't syntax sugar

They aren't syntactic sugar? Pretty sure `class Foo { blah() {} }` is equivalent to `function Foo() {}; Foo.prototype.blah = function() {}`.

Re:TypeScript Is Surprisingly OK for Compilers by bornfreddy on Friday August 18, 2023 @06:20AM (#37173641)
> the fact they aren't syntax sugar over prototypes was a mistake

Totally different meaning.

Re:TypeScript Is Surprisingly OK for Compilers by shrimpx on Friday August 18, 2023 @06:22AM (#37173652)
What else would 'syntax sugar over prototypes' mean?
Re:TypeScript Is Surprisingly OK for Compilers by zdragnar on Friday August 18, 2023 @10:15AM (#37175907)
There are a few very specific differences. In a subclass, 'this' doesn't exist until you call "super" for example, and the constructor will throw an error of invoked without the "new" keyword. [O]

These differences let you extend built-in things that simply can't be done with old prototype constructor syntax. [1]

[O] I should probably be using a more recent reference like MDN, but the 2ality series always sticks out in my mind whenever "just syntax sugar" comes up: https://2ality.com/2015/02/es6-classes-final.html#safety-che...

[1] https://2ality.com/2015/02/es6-classes-final.html#subclassin...

Re:TypeScript Is Surprisingly OK for Compilers by shrimpx on Friday August 18, 2023 @03:58PM (#37181260)
Thanks. It sounds like subclassing built-ins is where transpilers hit a hard wall. Other syntactic features of es6 can be transpiled.
Re:TypeScript Is Surprisingly OK for Compilers by zdragnar on Saturday August 19, 2023 @10:06AM (#37188913)
http://kangax.github.io/compat-table/es6/

This page lists features from es6 (and newer versions linked at the top) along with compliance to the spec. First column is the current browser, second is babel+corejs polyfills.

Overall, babel gets about 70% of the way there.

Re:TypeScript Is Surprisingly OK for Compilers by cxr on Friday August 18, 2023 @10:40AM (#37176302)
[delayed]
Re:TypeScript Is Surprisingly OK for Compilers by junon on Friday August 18, 2023 @11:38AM (#37177122)
They are not, no.
Re:TypeScript Is Surprisingly OK for Compilers by shrimpx on Friday August 18, 2023 @04:00PM (#37181298)
My example is incorrect because it doesn’t cover all the edge cases but you can desugar es6 to es5, except in es5 you can’t subclass builtins.
Re:TypeScript Is Surprisingly OK for Compilers by baq on Friday August 18, 2023 @06:10AM (#37173574)
you can still write the old javascript. it'll feel very lonely, though.
Re:TypeScript Is Surprisingly OK for Compilers by usrusr on Friday August 18, 2023 @07:42AM (#37174344)
Yeah, having just jumped into ts after a long js hiatus since back when The Good Parts was still surprising, it's quite awesome to see how much of what I assumed to be "ts stuff" is actually just postdeluvian js. Makes ts more attractive, not less. I do wonder however of it was possible to identify parts of that language superset that are fully redundant (as in not even required for exotic edge cases) and let loose some draconian linter?
Re:TypeScript Is Surprisingly OK for Compilers by jakubmazanec on Friday August 18, 2023 @09:28AM (#37175319)
Re:TypeScript Is Surprisingly OK for Compilers by usrusr on Friday August 18, 2023 @12:16PM (#37177826)
Sure, but that's still seems quite mix and match, anything goes, choose your own adventure. There are many positives about this approach, but as a learner a little more common ground between codebases would certainly be appreciated.
Re:TypeScript Is Surprisingly OK for Compilers by jakubmazanec on Saturday August 19, 2023 @10:46AM (#37189339)
True. I always thought that we should have additional mode stricter than https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe....