News for hackers. Stuff that matters.
Re:The Saga of the Closure Compiler, and Why TypeScript Won by noelwelsh on Thursday September 28, 2023 @04:20PM (#37695256)
From what I recall, the Closure type system wasn't well suited to Javascript. I recall it as being quite Java-ish (nominal rather than structural). It's been a loooong time since I looked at it, though, so I might be misremembering.
Re:The Saga of the Closure Compiler, and Why TypeScript Won by bananapub on Thursday September 28, 2023 @04:21PM (#37695272)
you're confusing Closure with Clojure
Re:The Saga of the Closure Compiler, and Why TypeScript Won by ramesh31 on Thursday September 28, 2023 @04:40PM (#37695526)
>You're confusing Closure with Clojure

No. Idiomatic Closure code was extremely Java-y. That was the whole point. Google built it to abstract away the nasties of early JS for their huge stable of Java programmers.

Re:The Saga of the Closure Compiler, and Why TypeScript Won by krackers on Thursday September 28, 2023 @04:21PM (#37695273)
It's just JSDoc though?
Re:The Saga of the Closure Compiler, and Why TypeScript Won by noelwelsh on Thursday September 28, 2023 @05:15PM (#37695985)
Right, but if you can't give precise types to common coding patterns the type system isn't very useful. A lot of work in Typescript is about being able to type the kind of things people do in JS.
Re:The Saga of the Closure Compiler, and Why TypeScript Won by paulddraper on Thursday September 28, 2023 @05:24PM (#37696097)
That is correct. It was heavily Java inspired. (And the compiler itself is written in Java).

But the same is true of JSDoc.

There weren't any popular type systems that weren't like Java.

---

Also, there are some notable departures, e.g. union types.

Re:The Saga of the Closure Compiler, and Why TypeScript Won by com2kid on Thursday September 28, 2023 @05:40PM (#37696266)
TypeScript aims to make a type system that can model anything you can do in JS. Of course JS can modify its objects, at runtime, in literally any way imaginable, so the TS type system has to be Turing complete. Anything less powerful and you aren't going to be able to model what arbitrary JS code is doing.

My go to example being a function that takes in an object with a bunch of camel case parameterFields and makes them into snake case parameter_fields.

Easy peasy in TypeScript, You can say, in a generic fashion, "pass an object with camelCase field names, and return the same object but the field names are snake_case".

This is incredibly useful when adapting between different systems!

Traditional OO systems fall flat on their face attempting such feats.

Re:The Saga of the Closure Compiler, and Why TypeScript Won by stevage on Thursday September 28, 2023 @06:37PM (#37696830)
Funny, I actually wrote and maintain a library which, amongst other things, does almost the same thing as your contrived example, except it's camelCase to kebab-case. It's written in Flow though, because that was what I knew at the time.
Re:The Saga of the Closure Compiler, and Why TypeScript Won by com2kid on Thursday September 28, 2023 @06:55PM (#37697026)
> does almost the same thing as your contrived example

Sadly, not contrived!

Anyone using protocol buffers is actually familiar with this exact scenario. Not sure how the JS PB compiler handles things though, I never bothered to look under the covers.

Here is a random sample I found of both the types and the conversion code.

https://gist.github.com/alfrdmalr/faa012e421d9f7f60c3e6d2d32...

Re:The Saga of the Closure Compiler, and Why TypeScript Won by stevage on Thursday September 28, 2023 @10:14PM (#37698523)
Yeah, cool. In my case I didn't really get all the type stuff right - I was mostly using Flow to be able to generate documentation.
Re:The Saga of the Closure Compiler, and Why TypeScript Won by simonbw on Thursday September 28, 2023 @08:27PM (#37697814)
I thought I was pretty good at TypeScript, but I can't imagine how I would write that function. Would you mind sharing that?
Re:The Saga of the Closure Compiler, and Why TypeScript Won by com2kid on Thursday September 28, 2023 @10:27PM (#37698602)
See my above reply

https://gist.github.com/alfrdmalr/faa012e421d9f7f60c3e6d2d32...

IIRC in one of the "what's new announcements" from the TS team included sample code to do it as well.

Edit: here is another example of doing it https://gist.github.com/kuroski/9a7ae8e5e5c9e22985364d1ddbf3...

And here is a medium article walking through the code step by step https://medium.com/@fullstack-shepherd/typescript-transformi...

Re:The Saga of the Closure Compiler, and Why TypeScript Won by EdwardDiego on Friday September 29, 2023 @04:26PM (#37709699)
That's horrifyingly awesome.
Re:The Saga of the Closure Compiler, and Why TypeScript Won by sizediterable on Friday September 29, 2023 @03:24AM (#37700363)
I don't know if its aim is necessarily to model anything you can do in JS. At the moment, TypeScript has zero understanding of prototypal inheritance and there hasn't been any visible progress in that direction.