In what cases is Javascript better than Typescript except for the learning curve????
Posted by Gullible-Clothes-433@reddit | learnprogramming | View on Reddit | 15 comments
So, I'm a casual learner, and I've learned python and c++. I need to learn a frontend programming language. Recommend me one and try to list the advantages of each one. Also, I've heard big companies are ditching TS. Is that true??
HashDefTrueFalse@reddit
You've listed the only two, and one is just transpiled to the other. JS is essentially the only game in town for front-end web. You'll need to know it no matter what else you use.
Types are extremely helpful and TS is a fine language in itself but the cracks show quickly IMO. On a greenfield project I'd rather have it than not, but I prefer my team use it minimally. IMO/E people try to do/check/prevent/enforce FAR too much with the type system, and burn time doing nothing useful. I've seen plenty of people online and in person tie themselves in knots trying to do pointless bits of metaprogramming to get the thing to do type gen or throw errors if a future dev writes certain code. It's particularly painful to introduce to large brownfield projects IME (half a dozen experiences over the last decade) that do bits of type juggling etc. I've vowed never to add it to an existing project again, as the reward is just worth the effort and by the time you realise you'll be left with a ton of casts and
anys you once thought temporary. It also feels clunky when you're pulling a load of typedefs (which are often just superficial interface defs) from a separate package and trusting that they're good. Multiple types are just a mistake IMO. I never use them and I don't think they should exist.number | stringor an object/interface where each prop isatype | null | undefined... yeah, thanks for that. If your datastore is also like that then god help you all.Some are, many aren't. It doesn't really affect anything for you. If you know JS very well then learning to use TS productively is a few hours reading and playing around. It's not a big investment.
Gullible-Clothes-433@reddit (OP)
So, javascript is the programming that runs on browsers and typescript helps us to make it safer with static typing and is easier to debug and finally convert ts code into js. Is that the purpose of Typescript??
HashDefTrueFalse@reddit
Yes, that's right.
Gullible-Clothes-433@reddit (OP)
So hypothetically, let's assume I write code perfectly with no need to debug and no one else needs to understand my code, then is Javascript better than Typescript!?
HashDefTrueFalse@reddit
Ignoring that that's not the most realistic scenario, it would simply be down to your preference. If you're the only one working with the code you can use whichever you like best. Comparing languages in a vacuum is a pretty pointless exercise. Words like "better" don't really mean anything without a ton of context. What are you building? What features would be helpful for that? Etc.
Don't get caught up on finding the "best", just learn JS and add on TS later if you want or need to. As I said, TS is very quick and easy to pick up if you already know how to use JS, as it's a superset of it with some added features that work very similarly to languages you've already worked with. Those concepts are transferrable so you'll mostly be picking up bits of syntax.
Gullible-Clothes-433@reddit (OP)
I get your point, "best" wasn't the best term to use. But what I meant was, for me, typescript just felt like overkill so after stripping away it's advantages could Javascript better more beneficial (for me). I might actually end up learning both like you stated idk.
HashDefTrueFalse@reddit
I'm not sure how to answer (I don't know you very well 😃) except to say that using just JS without TS on top is a perfectly valid choice. There's no inherent reason it will cause problems if you are fairly disciplined in your JS programming and write good, clean code that doesn't overly rely on dynamic typing trickery. This was standard for more than 20 ish years and many projects are built this way. As you mentioned, there are some people/places pulling back on it's usage after having similar experiences to mine or because they simply prefer JS. TS is the optional one, JS isn't (for web front-ends).
Gullible-Clothes-433@reddit (OP)
Thanks for clarifying ☺️👍
Remuz@reddit
I don't disagree with everyting you said but your examples seem to be how to implement TS badly. Yes you can easily write bad code with TS and minimize it's usefulness and there's are lots of projects that do that for sure. But you can do that with any programming language. TS can also be written without using such bad patterns. If TS is written like that then yes it's probably better to just use JS.
HashDefTrueFalse@reddit
I'm not sure what you disagree with, because I agree with all that you said.
Yes, examples of how most of the TS projects that I've personally worked on (over a dozen, of varying sizes, across several businesses) have used the language badly, and how the language encourages that in some places. That was my point.
Yes, I said that. That's why I advocate for more minimal usage of it.
Sure, that isn't really relevant to anything I said. Experience has led me to form the opinion that TS is most useful when used minimally, and from the start. That was the gist. I'm not trying to say TS is a bad language. I said it's fine.
I personally just use type annotations, disallowing (as most popular languages do) multiple types for a single datum, preferring that values remain the same for their lifetime and are annotated accordingly. So essentially I write explicitly typed JS and benefit from the compilation passes, and I encourage my juniors to do similar.
Headpuncher@reddit
That’s so nail on the head in my experience too I have to agree 100%, an upvote wasn’t enough.
FlashyResist5@reddit
Don’t need to mess with the build step, just runs as is.
DrShocker@reddit
If you made the choice to only use typescript, you could do your entire career that way if you wanted.
It's good to use a little of the thing 1 level lower than you so you understand what's happening if things go wrong though.
ImprovementLoose9423@reddit
Use JavaScript when:
- You need quick prototypes
- Flexibility
- Zero Step Build Process
- You are building a small project
- You need to use Dynamic APIs and Data Structures
- Building Zero-Config Environments
Gullible-Clothes-433@reddit (OP)
Thanks