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.
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.