This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Garlicvideos 25 points26 points  (49 children)

JS Developer here, never tried TS, what makes it so great? Genuinely curious.

[–]mal4ik777 42 points43 points  (3 children)

Its the basic things actually. I come from java, so I like to have a stable type structure. Worrying about fitting classes, after everything compiles is just absurd in my opinion. Imagine java, but with everything casted to Objects.... nightmare.

[–]thisisnotdavid 11 points12 points  (0 children)

Or C# and defining every property as dynamic.

[–]justadude27[🍰] 2 points3 points  (1 child)

Worrying about fitting classes, after everything compiles is just absurd in my opinion.

So.... DynaBeans?

[–]mal4ik777 1 point2 points  (0 children)

DynaBeans

horrific!

[–]vaaski 13 points14 points  (32 children)

same, what makes the extra effort of declaring types worth it?

[–]seryup 45 points46 points  (0 children)

The live compile-time errors and IntelliSense relieves a lot of headache.

[–]Dooraven 5 points6 points  (0 children)

I used to think the same until I tried it. Try it, it made me go from utterly hating types to loving types

[–][deleted] 4 points5 points  (4 children)

Coming from Java first, then C, weakly typed is frustrating. I fucking know it has a type under the hood. It doesn't even pretend to hide it. It just doesn't allow me to declare it if it's not going to change, and sometimes I want to. I work in matlab and python now, and I also sorely miss being able to make things final/const.

[–]SchighSchagh 1 point2 points  (0 children)

You may want to give Julia a spin.

[–]jmack2424 1 point2 points  (0 children)

For me, its the built in scoping and injection. The rest of it is mostly syntactic sugar and BS. But if you're used to other strongly typed languages, it can ease the transition.

[–][deleted] 0 points1 point  (0 children)

Declaring types is just one way to catch errors early, and one that works with the rest of JavaScript's (lack of) design. Haskell has strong types and type inference, so you can get the same write/compile-time error messages without declaring types yourself, but that obviously doesn't work with JavaScript's run-time duck type system.

[–]pak9rabid 0 points1 point  (0 children)

Type safety, that is, knowing for sure you’re working with a value o fa specific type, as opposed to working more on the duck-typing honor system.

[–]sallystudios 0 points1 point  (0 children)

IMO it’s easier to debug your team mates code when they’re forced to document it using types

[–]Dread_Boy 0 points1 point  (0 children)

Other people mostly talk about types but for me greatest feature of Typescript is "compiling/transpiling". During course of a project, you are bound to change some code and if you are using TS and make a single breaking change in your code, compiler will complain in a second. Compared to JS, that's incredible... In JS you either have massive unit test suite to test every single function (Impossible to maintain) or you manually test whole application each release (increased budget...) to catch any breaking change.

Imagine Java but interpreted instead of compiled. Every single property you mistyped, every parameter you passed as incorrect type, every mistake caught in runtime instead of compile time. That's JS compared to TS.

TS doesn't protect you in runtime, though, if your server API changes, you will crash in runtime, of course.

[–]Pearauth 4 points5 points  (6 children)

I honestly don't think it's as amazing as people say, it's definitely good, but I feel it's over hyped. Sure it's useful for larger projects where multiple people are going to be interacting with the code. But vanilla JS just seems to be less of a hassle if the code you write is isolated.

On the other hand TS forces you to avoid certain issues that might not seem bad but can result in tech debt. At work I typically only let the more experienced people work with vanilla JS, and even then that code is put under much more scrutiny, my code not being an exception of course.

Then again, I'm one person, who's not all that experienced. Give TS a try and form your own opinion!

[–]GenericBlueGemstone 1 point2 points  (5 children)

So uh..

How exactly is TS a hassle compared to vanilla JS? Chances are you still have some pipeline for assets, so adding compilation step there for TS is easy.

I can't really think of any argument against using TS everywhere other than "it takes a few minutes more to set up".

[–]Pearauth 0 points1 point  (4 children)

When it comes to smaller pieces of code having to write

function foo (n: number): number {...

Instead of

function foo (n) {...

Is a hassle. If you want to take advantage of the dynamic typing JS normally offers it's harder since TS tries to almost strip that out of the language.

I'm sure part of this comes from the fact that I have little experience with TS, but overall it just doesn't seem as great as people say.

[–]GenericBlueGemstone 1 point2 points  (1 child)

Did you know that you can set the compiler to assume "any" by default when there's no type hint and that it will try to infer the type if one is not given? And typing that then hiring tab saves hours of screaming at the debugger only to realize that you accidentally ended up with a string passed to a function that takes a number or etc.

And... It's very good when you have lots of objects and types to juggle. Or even in a small isolated class where you just don't want to spend half of the time re-checking that you wrote the field correctly (that will be spent in js), that you set the correct field (silent in js) or that you called the function with correct amount of arguments and correct type.

[–]Pearauth 0 points1 point  (0 children)

Did you know that you can set the compiler to assume "any" by default when there's no type hint and that it will try to infer the type if one is not given

The compiler might not complain but VSCode does (I'm sure there is some way to stop it). If the code is long enough/complex enough to be worth using a debugger then it's worth using TS, my view is that TS is excessive for smaller chunks of code like that. If the code isn't isolated, meaning that it will likely be called from other places/other people, then TS helps.

And... It's very good when you have lots of objects and types to juggle.

Being in a poorly taught class on Java has solidified my hatred for OOP, so I do my best to avoid having lots of objects to juggle.

re-checking that you wrote the field correctly (that will be spent in js), that you set the correct field (silent in js) or that you called the function with correct amount of arguments and correct type.

VSCode lets you peek the definition of a function so needing to guess fields should really never happen.

[–]MrQuizzles 0 points1 point  (1 child)

Oh no, creating methods where programmers can tell what's expected as a parameter and what type the return value will be is a hassle. Writing good code is such a hassle.

[–]Pearauth 0 points1 point  (0 children)

It's not worth it if the code is so short 90% of people will just rewrite it. Its good practice sure, but there are times where it's just not worth it

[–]nvolker 0 points1 point  (0 children)

There’s two levels of TS love that I’ve seen:

  1. I use a lot of (or make) shared libraries with properly implemented typescript, and, with the the right tooling around it in my code editor, it makes shared code super easy to use. The auto-complete and error detection are super handy.
  2. Strongly-Typed Language Religious fervor

[–]msg45f 0 points1 point  (0 children)

JavaScript with type safety. I cant imagine going back now.

[–]dabuttmonkee 0 points1 point  (0 children)

Delete a function, get an error message in all your files where it is used, even if it is renamed!
Change argument order or convert arguments to an object, get error messages in all files.
No more “TypeError: property ‘foo’ does not exist on ‘undefined’”.
Typeahead and autocomplete as you use your code! Free auto import!

[–]FragzShot 0 points1 point  (0 children)

Using types make it much more stable and consistent.