this post was submitted on 18 Oct 2023
329 points (96.1% liked)

Programmer Humor

32594 readers
1234 users here now

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

Rules:

founded 5 years ago
MODERATORS
 
all 34 comments
sorted by: hot top controversial new old
[–] [email protected] 87 points 1 year ago (6 children)

Might as well not use TypeScript

[–] [email protected] 42 points 1 year 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?

[–] [email protected] 8 points 1 year ago

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

[–] [email protected] 12 points 1 year 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.. :/

[–] [email protected] 10 points 1 year ago

That's the joke

[–] [email protected] 3 points 1 year ago (1 children)

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

[–] [email protected] 3 points 1 year ago

Cause otherwise it's plain JS :/

[–] [email protected] 3 points 1 year ago (1 children)

I don't follow, stamping every function with : any lets you merge the branch and deploy it... trying to properly type everything extends the initial migration time likely to a level where management just says no.

[–] [email protected] 7 points 1 year ago* (last edited 1 year ago) (1 children)

Use a combination of allowJs and ts-ignore, do progressive enhancement, and convert your codebase file by file. Adding any everywhere literally turns off type checking altogether codebase wide, including type inference. It also means a huge PR that's both just noise that needs to be fixed later, and messes with your git history (good luck getting anything useful out of blame or bisect now).

Just getting a green build doesn't mean things are okay. You're worse off than before doing that.

[–] [email protected] 4 points 1 year ago* (last edited 1 year ago)

I disagree that you're worse off (the core of my comment was that even a shitty migration encourages better practices)... but I wasn't super familiar with TS hinting - using ts-ignore would be preferable.

Personally, I mostly work in PHP and we use a similar system. Strict typing is default off so we've slowly propagated declare(strict_types=1); to enable compile and runtime checking on a per file basis.

[–] [email protected] 2 points 1 year ago (1 children)

Forreal. Even a bespoke inferred return type is better than any 9 times out of 10.

[–] [email protected] 4 points 1 year ago

This is the only reason I haven't pushed my team to switch. I'm worried too many of them will be OP.

[–] [email protected] 54 points 1 year 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.

[–] [email protected] 21 points 1 year 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

[–] [email protected] 11 points 1 year ago (1 children)
[–] [email protected] 8 points 1 year ago

But it’s “a colon any” 🧐

[–] [email protected] 7 points 1 year ago

I knew my any key would be useful one day.

[–] [email protected] 2 points 1 year ago

Why not use assembly ?

[–] [email protected] 2 points 1 year ago

Typing < type hinting

[–] [email protected] 1 points 1 year 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.

[–] [email protected] -5 points 1 year ago

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