this post was submitted on 18 Oct 2023
299 points (96.0% liked)

Programmer Humor

32410 readers
1 users here now

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

Rules:

founded 5 years ago
MODERATORS
 
all 25 comments
sorted by: hot top controversial new old
[–] folkrav@lemmy.world 78 points 2 years ago (4 children)

Might as well not use TypeScript

[–] PoopMonster@lemmy.world 37 points 2 years ago (1 children)

Just as irritating as seeing people use linters only to have a lot of files with @ts-ignore all over the place... Like why even bother?

[–] master5o1@lemmy.nz 7 points 2 years ago

oh you've got a private variable that I want to use? No worries, (foo as any)['secret'].

[–] fusio@lemmy.world 11 points 2 years ago

using any is actually much worse than using TS, because you're basically telling the compiler "don't help me here".. at least with JS the IDE is gonna help you.. :/

[–] seeyouinteawhy@lib.lgbt 9 points 2 years ago

That's the joke

[–] chicken@lemmy.dbzer0.com 3 points 2 years ago (1 children)

tbh I don't remember why I'm using TypeScript

[–] folkrav@lemmy.world 4 points 2 years ago

Cause otherwise it's plain JS :/

[–] alokir@lemmy.world 51 points 2 years ago (2 children)

It's a good way to get started, and then incrementally type as much as you can, preferably everything.

Later on, or if you start a new project with TypeScript, it's a good idea to turn on noImplicitAny and only allow explicit any in very specific framework level code, unit tests or if you interface with an untyped framework.

The hassle really pays off later.

[–] fusio@lemmy.world 21 points 2 years ago

this is terrible advise - you should be using unknown. using any you're basically disabling TS and will be under the false assumption that your code is ok while it's most likely missing a lot of runtime checks

[–] scrubbles@poptalk.scrubbles.tech 10 points 2 years ago (1 children)
[–] some_designer_dude@lemmy.world 8 points 2 years ago

But it’s “a colon any” 🧐

[–] Spoilt@jlai.lu 7 points 2 years ago

I knew my any key would be useful one day.

[–] topinambour_rex@lemmy.world 2 points 2 years ago

Why not use assembly ?

[–] ABC123itsEASY@lemmy.world 1 points 2 years ago

Nah this isn't the way, friend. Instead of adding a bunch of useless anys all over the place, start typing in one part of the application and exclude the rest using a path pattern. Or simply allow .js and only change the extension for files you've typed. Doing this is just wasting time and creating false assurances of type safety.
It's not that hard to define correct, meaningful types. Often vscode already has implicitly determined them for you; just mouseover the variable.

[–] Max_P@lemmy.max-p.me -4 points 2 years ago

I wish I did that, at this point my TypeScript template errors are as long as C++'s ._.