ProgrammerHumor

watchHowILoveToDeclareEveryInterface

watchHowILoveToDeclareEveryInterface

I do kinda love it though. My IDE knows what properties and methods the object should have.

https://i.redd.it/8twhalvj2acf1.jpeg
Reddit

Discussion

StinkyStangler

People who complain about typing in Typescript are just bad at writing software and you can’t change my mind

You should know what every function expects as an input and output and you should know what every variable will be. Not sure why this is controversial to so many devs lol

8 hours ago
Solax636

pretty sure all these typescript memes are from people that dont have a job yet where you have to think about maintaining software and not just 420 blaze it a hackathon project in a day

6 hours ago
TrashfaceMcGee

I go through onto a ~12k LoC tsx codebase and it was truly abysmal the number of “:any “ and “as unknown as T” I saw. To the point where we even had the api definition in redux defined as “const api: any = createAPI”. Some Typescript developers hate types so badly I wonder why they even bother

4 hours ago
Front-Difficult
:ts::js::py::m::bash:

Add a "@typescript-eslint/no-explicit-any": "error" to their eslint rules, and let them train themselves to be better.

3 hours ago
splinterize

Then watch each new file that you open become red and throw infinite linter errors, I love doing that

1 hour ago
paxbowlski
:ts: :js: :hsk: :bash:

hAvInG tO aLwAyS dEfInE tYpEs sLoWs dOwN dEvElOpMeNt tImE

5 hours ago
Ashtefere

Well, it does. A lot. But it saves much more maintenance time than the dev time cost.

3 hours ago
Front-Difficult
:ts::js::py::m::bash:

I actually disagree. It also speeds up development time when you reuse the code. It speeds up both.

Especially when working in teams, but also when reusing code you wrote.

3 hours ago
The_Real_Slim_Lemon
:cs:

It’s the same argument for unit tests - unless you’re a gigachad that gets everything right the first time, having a few tests for each change speeds up dev time.

2 hours ago
madcow_bg

Also, you need to be a perfect predictor of what the future needs of the software will be. Nobody can be that lucky.

43 minutes ago
Ashtefere

If you are forgetting what types your functions need and output while you are developing a new feature, you are doing too much at once (or need to see a doctor!)

Once your working prototype of your feature is proven, thats the best time to put in types and unit tests. Otherwise you are creating railroads as you go and it’s discouraging you from doing rapid rewrites and direction changes during prototyping and discovery - and if you DO need to change direction often you are likely writing (and rewriting) more lines of types than code per hour. So, empirically when writing a new feature that needs experimentation, you will take a lot less time if you dont type it as you go.

Thats not to say thats a good thing or the right approach, its just simply what will happen.

There are better techniques to use when developing large features from scratch though, and typing as you go is probably one of the least effective of them.

When you do fully complete your feature and merge it in, you 100% should have it fully typed and unit tested though!

2 hours ago
Nutasaurus-Rex

What lol? This is incredibly common. I’ll barely remember functions or features I wrote 1-2 years ago. Nobody remembers everything they programmed. Especially if they end up working for different companies, handling different codebases. To be honest, the only person that would say they don’t forget their code is someone that is too new to the industry to forget

2 hours ago
Ashtefere

Im talking about while you develop a feature for the first time (eg make a button that sets something). For maintenance of old code, it should be already typed. Maybe read the comment again?

2 hours ago
Architektual

You're 100% right, I'm saying this as someone with 15 years of web experience.

1 hour ago
Nutasaurus-Rex

I sorta agree with his current post now too, but it’s not what he posted an hour ago lol. Everything past the first paragraph is new. Also, in no way does his edited post of his current coding style conflict with typescript so I don’t know why he’s arguing against typescript in this case

53 minutes ago
Ashtefere

No edits have occurred on my post, you can check. Maybe your app bugged out?

51 minutes ago
Nutasaurus-Rex

Bruh you’re actually trolling, you just edited your comment after my post 😂 I’m done with this

56 minutes ago
Ashtefere

Maybe you responded to the wrong comment? My comment hasnt been edited, you can check.

50 minutes ago
splinterize

I barely remember features that I wrote a few hours ago tbh

1 hour ago
Front-Difficult
:ts::js::py::m::bash:

Who goes back over their code after they're finished to add types - that's crazy.

Your types shouldn't be changing meaningfully while re-writing your code, I don't understand what you're talking about. I have no point of reference for the experience you're describing.

But I have, many times, started a new day by coming back to a piece of code I was working on the previous afternoon and had no recollection of what I was doing or why. I don't think that's indicative of me needing to see a doctor. Of course it'll come back to me - but types and docstrings are my best tool to get back to 100% productivity at the start of the day. Write your types, tests and documentation as you go, it's much much faster.

49 minutes ago
Ashtefere

How bout an example?

Say I am developing a feature that takes an array of hashed strings for a store of some kind.

I build the feature and its supporting functions during the day/week and then realize i need to change the entire tree of functions to support an array of objects instead to store more things, like subscribers/etc.

How much types have i written yesterday that are now invalid?

Imagine that the functions change significantly over a daily basis while i figure out how to solve my problem.

Isnt it quicker to just solve the problem first?

41 minutes ago
Front-Difficult
:ts::js::py::m::bash:

For starters, I don't think that's a very common issue. You should generally work out the entities you need before writing any code, and so you should know if you need an object or not before starting. It seems unlikely your store changes from needing a single hash, to a hash plus metadata. But regardless, we've all been there at least once, so I'll engage with the example.

You need to alter one type. Only one type is invalid.

Reuse your code. If you have a type that describes a specific entity for a store, even if its just string[], abstract it into a named type in a types file. So your code shouldn't look like:

function someService(arg: string[]) {
  updateStore(arg);
}

function updateStore(arg: string[]) {
  // Do something with arg
}

function getStore(): string[] {
  // Retrieve array
}

it should look like:

function someService(arg: SomeStore) {
  updateStore(arg);
}

function updateStore(arg: SomeStore) {
  // Do something with arg
}

function getStore(): SomeStore {
  // Retrieve array
}

type SomeStore = string[];

Now, when you need to refactor SomeStore you just edit the one type, you don't need to go back through every function that ever called it. And now, if you miss something during the refactor that still treats arg like an array of strings you'll get a helpful red squiggly to point out "Hey! You missed this bit of code!". And that will speed up your development too.

31 minutes ago
beclops
:sw:

Yeah it’s like objecting to having an enforced code style guide or unit tests. It’s a bit suspicious if a dev takes such strong issue with these things because if they really interfere that much with their development process they were probably writing crap to begin with

5 hours ago
TheNinjaFennec

I mostly work in Java, so when I have to do stuff in typescript I’m obviously bringing some bias with me, but I can’t stand it. Everything about the way the language is structured seems to move against the current of strong typing. It feels like trying to jam a star shaped box into a little rectangle hole; squeeze enough and you can get the corners situated in there where they need to be, but it’s a pain to do so and the end result looks ridiculous.

4 hours ago
polokratoss

I mean, TS is bringing types to JavaScript. I don't think one should hold JS's bullshit against TS.

2 hours ago
Rustywolf

Writing types is the closest to TDD i will ever get, and i like it this way

4 hours ago
TomWithTime

You should know what every function expects as an input and output and you should know what every variable will be.

I'm so good at this part that I don't even need typescript!

3 hours ago
Zeilar
:js::p::ts:

But it's an extra build step!!!

59 minutes ago
Divs4U OP

Personally I think it comes from being used to Javascript as kinda loosey goosey. Suddenly you can't just let it infer everything.

editing this because apparently people don't understand my comment is referring the "people who complain about typing" in the previous comment. I'm saying they may have started out with js before moving to ts and they have to adjust how they do things.

I'm not complaining about typescript, I love it as the meme says.

8 hours ago
MornwindShoma

"Inferring" is all TypeScript behind the scenes. Back in the day... You had to guess it. The editor wasn't telling you shit. You were lucky if it knew the methods for global objects. People who complain about it never lived without TypeScript in the first place.

5 hours ago
StinkyStangler

Yeah I mean that’s how things break in production haha

Typescript is really just better JavaScript. I originally was opposed to TS when I switched over from JS but that was because I used to be a way worse software engineer than I am now lol

6 hours ago
Sbadabam278

And that means you’re a bad programmer :) no offense, maybe you’re just very junior, and that’s totally fine. But anyone who was ever done serious work on a large code base knows that typing is essential.

6 hours ago
Divs4U OP

I wasn't even talking about me. I'm talking about people who start with Javascript and move on to typescript and it's different. Try not to be so rude.

6 hours ago
Sbadabam278

Apologies for being rude, I didn’t mean to. But I do want to forcefully reiterate: it is my strongly held opinion that if you don’t see a big difference between typescript and JavaScript, and “kinda prefer the latter”, then you know nothing about software engineering (maybe simply due to being junior, but still)

6 hours ago
Divs4U OP

Man I'm glad I dont care about the opinions of internet strangers

6 hours ago
anonymity_is_bliss

Yeah that's why you posted this here right?

Because you don't care about people's opinions on the post.

5 hours ago
Sbadabam278

good!

5 hours ago
MissinqLink
:js::g::hamster::j::py::holyc:

I don’t disagree with your concepts. I just like to have no build.

4 hours ago
deljaroo

If given the option not to use typescript, I basically always turn it down. JavaScript's typelessness is annoying, but the documentation and stack overflow for typescript is like five times harder to google. And maybe I am bad at writing software because I rely on googling how to do things all day; but it pays the bills, and people are happy with my work.

1 hour ago
bigorangemachine

Yes but the mistakes you make with typescript still requires you to understand the language you are writing in.

I can't the number of times people think that typing a string as a number converts it under the hood. It really bothers me that people think that because they know typescript they'll make less mistakes... they just make different mistakes.

Plus in the codebase I'm working on we are under the tyranny of any.

Personally I prefer to just turn off TS and just knock out the code but the untangling of TS errors is a larger headache. I had some issues last week where typescript couldn't understand an array I was spreading into a knex.where() and I defined it as only 2 or 3 items in the array and keeps saying the types were wrong.

A side effect of my team getting on TS is people stopped attaching debuggers to the node-server because no one really wants to learn how the node args map to to these layers of developer tools... or develop inside a docker container to debug a cloud environment :\

5 hours ago
hammonjj

That’s because typescript is not a great solution. It’s a bandaid around JavaScript. The industry needs to move to typed languages from the beginning (hot take but I love dart and flutter web has a lot of promise if Google actually did something with it)

4 hours ago
Rustywolf

Share your array issue cause it seems like something that should be no issue

4 hours ago
bigorangemachine

I would for now it's got a spicy @ts-ignore.

The block was just like

const query = knex('table').select({...}); const wheres = []; if (primaryKey) { wheres.push([{ id: primaryKey }]); } if (status) { wheres.push([{ status }]); } else { wheres.push(['status', '!=' 'hidden']); } if (wheres.length > 0) { wheres.forEach((where, i) => { query[i === 0 ? 'where' : 'andWhere'](...where); }); } The forEach is very cranky. I worked with Chat-GPT with minimal code samples and couldn't figure it out. It ended up with the same error even when I give an explict type.

For now I'm chaulking it up to not being able to upgrade TS in our codebase but I imagine this would have been frustrating to deal with before it was updated... I just ignored and moved on.

4 hours ago
Rustywolf

First thing that stands out is that your array is going to be typed as an empty tuple, so pushing values i to it wont work as expected.

4 hours ago
bigorangemachine

Ya I made a Type that reflected exactly that went into it.

As it is it doesn't run the forEach block. Either way wasn't worth spending the time to fix it.. I did TDD on it even with empty array and no problems. Just a false positive.

4 hours ago
Rustywolf

Typing a string as a number will atleast throw an error immediately instead of unexpected behaviour... which is entirely the point.

4 hours ago
bigorangemachine

No Like people think using ` as ` is the same as parseInt/parseFloat

Everytime I point this out I have to have a conversation about how typescript only protects the buildtime.. not he runtime.

4 hours ago
Rustywolf

Oh yeah okay i can see how that could come up, though doesnt TS complain about no type overlap and require casting through unknown?

4 hours ago
bigorangemachine

I'm not sure.

As a consultant I'm honestly horrified everytime I join a team and I see ` as number` spammed thinking its syntax magic really bothers me.

Other times I got people discouraging instance of checks not understanding that instanceof is a better test than trusting TS.

4 hours ago
BlindTheThief15

Typescript is GOATed. I love knowing what my functions require and what they will return. I love knowing what types my variables are.

3 hours ago
YouDoHaveValue

Refactoring is where strict typing really shines.

You basically just start breaking shit and the red lines tell you what to fix.

1 hour ago
Divs4U OP

LOVE IT

3 hours ago
darklightning_2

Typescript is a solution to a problem which should have never been there. Decoupling the types from the code was and still a bad idea but its better than nothing

10 hours ago
Charlieputhfan

Can you explain what does that mean in context of js/ts

10 hours ago
SpookyLoop

"JavaScript should've had types to start with" is all the original commenter is really saying.

More specifically, JavaScript is pretty object oriented. It's multi-paradigm, but still, a lot of what we're doing is reading /writing objects.

Handling objects without a type system is just kind of insane. Everything from code smells (relatively minor bad practices) to major issues comes from not having a type system.

Like literally just now, I had to adjust some touch events in an old codebase that uses an old version of jQuery. I have to fly completely blind, do a ton more Googling, and make a lot more errors / work significantly slower than I would if everything was typed and if my LSP could do more to guide me.

8 hours ago
SillySlimeSimon

js has dynamic typing, and type issues only come up once the code is run.

Compare that to other languages that check typing at compile time and catch issues before the code is even run.

ts alleviates it somewhat by adding type annotations that enable some form of type checking, but you can still get type errors on execution since they’re only annotations and compile down to js in the end.

Just how it is when you don’t have strict typing.

8 hours ago
Charlieputhfan

similar issues with python ? pydantic is a fake typing as well

8 hours ago
SillySlimeSimon

yes

8 hours ago
SuspiciousBread14

Imagine JS as TS, but you can only use type any

6 hours ago
TheMaleGazer

Typescript's goal is to trick you into believing it knows things at runtime that it actually doesn't, no matter how many times you have to remind yourself that it's all JavaScript underneath.

7 hours ago
alteraccount

If it's tricking you, then you're doing it wrong. Typescripts goal is to allow the programmer to declare what he/she knows about things at runtime. It's a developer tool, it allows you to declare to yourself what you know about the code and how it should behave. It's only saying back to you what you have said to it.

5 hours ago
TheMaleGazer

Every problem with a language is one that makes it easy to use it wrong.

1 hour ago
Kitchen_Device7682
:sc:

No language knows the runtime. You may compile with libraries that are missing at runtime. But you mean if you put any and ! all over the place you may end up tripping yourself?

5 hours ago
vm_linuz
:ts::rust::fsharp::hsk::clj:

Some people like decoupled types.
It's best to see them like unit tests.

8 hours ago
RingEasy9120

Every JavaScript/typescript/python meme in this subreddit read like someone who's never written anything with more than 3 function calls before. 

5 hours ago
MaybeIsaac

Real talk

2 hours ago
fantastiskelars

Typescript is amazing. The only issue i have with it, is when people bloat their project with types from all these code gen tools. It is down right the most horrible experience to work on a project that have multiple code gen tools that have generated close to 1 million types and you now have to wait 30-60s on every single auto complete to trigger

6 hours ago
BeautifulCuriousLiar

That sounds like a nightmare

4 hours ago
kooshipuff

I get a lot of people aren't fans. I kinda love it, but I also use it in a very different way- it gives you a pretty clean, modern, object-oriented scripting language with an actually really robust type system (including decorators that can actually execute code when a type comes into context, replace members, etc), great IDE support including sourcemaps that work with a visual debugger, and it can transpile all the way down to ECMAScript 5. It can probably go lower, but ECMAScript 5 is important.

There are lots of native libraries, including some really small ones with basically no external dependencies, that can run ECMAScript 5 (but not 6!) really fast, including even precompiling it.

If you're developing an application that needs object-oriented scripting support (ex: a game engine), it's an extremely strong contender with a basically unbeatable combination of language features and portability (and not too shabby on execution speed if the transpiler output is precompiled to an interpreter-specific bytecode.)

10 hours ago
rover_G
:c::rust::ts::py::r::spring:

Use type inference and rely on types/interfaces as needed. Unless you are authoring a library or using decorators, most of what you need to do in TypeScript can be accomplished with functions and typedefs only.

10 hours ago
Rustywolf

Functions are 90% of my type definitions, including interfaces for params/returned values

4 hours ago
Global-Vanilla-9319

It's like Stockholm Syndrome, but for your codebase. And it actually helps.

10 hours ago
yesennes

I love you in a prison of your design though. When you get out you break my code.

5 hours ago
Ok-Visual-5862
:cp:

What I love about C++ in Unreal Engine is because all the types are there, any time I see something in the codebase that's new, I can easily navigate to it in my IDE and discover how it works better and sometimes I even learn a cool new trick in how to do something in my games.

I cannot understand how people can work with every variable is var or let.... I can't even read it.

3 hours ago
KorKiness
:cs:

What do you mean "prison of your own design"? You always living in your design. Strict typing is just clearly shows your design back to you.

16 minutes ago
DasKapitalV1

If it is to suffer... Js + Jsdoc >>>> typescript.. if you disagree. Skill issue.

3 hours ago
Zeilar
:js::p::ts:

TypeScript offers more functionality.

52 minutes ago
Big_Orchid7179

"TypeScript: because who needs freedom when you can have strict type checks and existential dread!"

10 hours ago
delayedsunflower
:cp::cs::py:

I get way more existential dread from the runtime errors that dynamic typing creates.

6 hours ago
mhphilip

I see Ren, I upvote

10 hours ago
ThoseOldScientists

My problem with TypeScript isn’t that I object to the concept of type safety in JS, my problem with TypeScript is that it’s fuck ugly.

5 hours ago
MeltedChocolate24
:c::j::ts::py::js:

Really? It looks like a sexy version of Java to me.

3 hours ago
Ronin-s_Spirit
:js:

That's why I write JS instead. I use jsdoc on things like functions to know what they want from me, and to occasionally leave a comment on some elements of the program - the main benefit is that I'm not obligated by typescript do add all these annotations for everything every time.

3 hours ago