Presi300
link
fedilink
English
-11Y

As someone who is relatively new to webdev stuff, I gotta ask… what is the point of typescript? Like, is it faster than JS, does it have more functions or smth? To me it just looks like JS with extra steps and a really, REALLY cursed way to declare variables.

Types help you prevent errors while writing the code instead of while running. That’s a massive benefit, as it literally makes a lot of errors impossible (as long as you don’t work around it) - otherwise you have to write a lot of tests to get the same guarantees, and you could always miss something by doing that.

The other benefit is that it allows other developers to understand your code very, very quickly. Types describe what your data looks like - there is nothing more important in programming than that!

When you install an NPM library and your editor gives you hints about parameter types, return types etc., that’s all Typescript types at work.

It helps for when you have a variable that’s for numbers and you use it as a string or something else, it shouts an error. In other words, it protects you from yourself

@aeharding@lemmy.world
link
fedilink
English
51Y

Report -> I’m in this picture and I don’t like it

I don’t like it but God help me if I try to bring up that we shouldn’t use it. I understand it I just don’t like how it slows everything down for in my opinion is not much gain.

I’d say its more like the gas tank telling you that you aren’t allowed to pour in brake fluid as that could lead to runtime errors.

tank.pour(brakeFluid as Any); // do not remove this for some reason will break prod

So much funnier

ShroOmeric
link
fedilink
81Y

I swear to god, sometimes I really don’t know what Typescript really wants from me. It’s like some old god: you know it needs a sacrifice but the god is not telling you exactly what he wants. So you can only try and pray.

Idk, I find it pretty easy to understand

The "return type <5 paragraphs of various word salads> is not compatible with " error messages are anything but easy to understand in my opinion.

@gornius@lemmy.world
link
fedilink
4
edit-2
1Y

Yeah I don’t get why it spits out whole types instead of only differences between them. Like “function expects non-null ‘some.param.in.object’ of type ‘string’ in argument ‘someArgument’, which is missing in passed argument”.

Guess it’s not only Typescript that likes to argue with the developer while missing the entire point…

Biologists: but tomato is a berry, which is subset of fruits

Create a post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
  • 1 user online
  • 5 users / day
  • 9 users / week
  • 108 users / month
  • 558 users / 6 months
  • 1 subscriber
  • 899 Posts
  • 3.11K Comments
  • Modlog