6 ms·
If JavaScript is "a giant pile of excrement," I think that makes TypeScript a polished turd. It's just a superset of JavaScript.
by vlunkr 3y ago
If JavaScript is "a giant pile of excrement," I think that makes TypeScript a polished turd. It's just a superset of JavaScript.
- baq 3y agoYeah typescript is amazing, the javascript below it is made out of evil hacks.
- vlunkr 3y agoThis is what I'm saying though. Typescript is just a hack on top of Javascript. The same engine is going to run your code in the browser. For the record, I think Javascript is fine (with some nasty warts), and Typescript is a great addition. The idea that TS is great but JS sucks is silly.
- anyfoo 3y ago> Typescript is just a hack on top of Javascript. Exactly, it makes it "more palpable". > The idea that TS is great but JS sucks is silly. Just to be clear, I absolutely did not say that. Instead, I'd rather agree with your statement that TS only makes things better. But there is only so much it can do in that ecosystem, even if a good type system does notably improve things. Everything that's below that is still what it was.
- anyfoo 3y ago> Exactly, it makes it "more palpable". Typo: Palatable, obviously, not palpable. Too late to edit.
- robertakarobin 3y ago> The idea that TS is great but JS sucks is silly. Isn't all programming just layers of abstraction that make the layers underneath it more usable? If you view Typescript as a standalone language that is another abstraction -- just like every other programming language -- that may make it more palatable. Yes, it's technically a superset of JavaScript, but I don't think anyone uses it that way. It would defeat the purpose, like buying a car and then tearing out the seats, air conditioner, and sound system.
- baq 3y ago> The idea that TS is great but JS sucks is silly. Actually... typescript's type system could work quite well in other languages and is in fact in some fashion being ported over to multiple, Python's great turnaround on type hints a few years ago was obviously inspired by it. So, I disagree. The type system makes a wart of a language into something passable, which is a great achievement.
- sk0g 3y agoJust curious, is there a way to define typed DTOs or things like Pydantic models, and then parse blobs of JSON into said classes, all leveraging the type annotations? I know it all gets compiled away in JS and all, but Pydantic is surprisingly ergonomic to use and type hints are sort of a suggestion, albeit available at runtime. Closest I've seen is Zod, but the syntax looks horrendous IMO. Maybe you look past it eventually though.
- MatthiasDev 3y agoType reflection with TypeScript is fairly limited at the moment, though what you are describing can be done with decorators. I have made such a library myself: https://github.com/decoverto/decoverto https://github.com/decoverto/decoverto Another library would be https://github.com/typestack/class-transformer https://github.com/typestack/class-transformer
- darken 3y agoAssuming I understand you question: you can define an interface to describe what an object parsed from JSON contains, and then cast your raw JSON-parsed object into that type. The casting doesn't guarantee the JSON from your server fits the interface, but it WILL ensure any downstream use is correct, and also enable auto complete for its fields (assuming your IDE supports it). I've been using JavaScript on and off for nearly 20 years, and TypeScript is a massive improvement.
- simplify 3y agoNo, it's actually quite good due to being the most advanced (and a pleasure to use) type system to achieve mainstream adoption.
- anyfoo 3y agoIndeed, adding a type system does a lot.