809
you are viewing a single comment's thread
view the rest of the comments
[-] JakenVeina@lemm.ee 95 points 1 year ago

I like TypeScript less for its ability to categorize my grocery list and more for its ability to stop anyone from putting cyanide on it.

[-] DrM@feddit.de 49 points 1 year ago

I hate Typescript for promising me that nobody can put cyanide on the list, but in reality it disallows ME from putting cyanide on the list, but everyone else from the outside is still allowed to do so by using the API which is plain JavaScript again

[-] CanadaPlus@lemmy.sdf.org 35 points 1 year ago

Honestly, programming is great for teaching you that you are the stupid one. This is still a feature.

[-] DrM@feddit.de 13 points 1 year ago* (last edited 1 year ago)

The main problem with JavaScript and TypeScript is that there is such a little entrybarrier to it, that way too many people use it without understanding it. The amount of times that we had major issues in production because someone doesn't understand TypeScript is not countable anymore and our project went live only 4 months ago.

For example, when you use nest.js and want to use a boolean value as a query parameter.

As an example:

@Get('valueOfMyBoolean')
@ApiQuery(
  {
    name: 'myBoolean',
    type: boolean,
  }
)
myBooleanFunction(
  @Query('myBoolean') myBoolean: boolean
){
  if(myBoolean){
    return 'myBoolean is true';
  }
  return 'myBoolean is false';
}

You see this code. You don't see anything wrong with it. The architect looks at it in code review and doesn't see anything wrong with it. But then you do a GET https://something.com/valueOfMyBoolean?myBoolean=false and you get "myBoolean is true" and if you do typeOf(myBoolean) you will see that, despite you declaring it twice, myBoolean is not a boolean but a string. But when running the unit-tests, myBoolean is a boolean.

[-] shasta@lemm.ee 7 points 1 year ago

This is more a condemnation of nest.js than ts. It seems great in theory. I like the architecture and the ability to share models and interfaces between front and backend, but it's objectively makes everything more complicated. It adds layers of abstraction that should not be necessary and it's such a niche/unpopular framework for backend systems that you generally have to jump through hoops to do anything moderately complex. Not only do new devs have to learn typescript to use it, they have to learn the nest architecture to know how to do things "the right way" and you still end up in situations like this which looks perfectly valid but isn't. Typescript was never meant to be used for backend, and trying to make it do so and then complaining about it is like jogging while carrying a gun, shooting yourself in the foot, and blaming the gun.

[-] zalgotext@sh.itjust.works 1 points 1 year ago

the ability to share models and interfaces between front and backend

On the other hand, this can be considered a downside because it locks you into using JS/TS on the front and backends.

Alternatively, if you define your models and interface with an Open API spec, you can write the front and backends in whatever language you want.

[-] CanadaPlus@lemmy.sdf.org 5 points 1 year ago

I've never used TS, and I'm not exactly sure what nest.js even does, but building a TypeScript project on top of a JavaScript library not designed for it seems like asking for trouble. Is that standard practice?

[-] sloppy_diffuser@sh.itjust.works 3 points 1 year ago* (last edited 1 year ago)

Yes. As of this writing there are 7,738 type definitions in a central repo maintained by users for plain JavaScript packages.

https://github.com/DefinitelyTyped/DefinitelyTyped

Many package owners write type definitions included with their package that is written in JavaScript also.

[-] CanadaPlus@lemmy.sdf.org 1 points 1 year ago* (last edited 1 year ago)

Web dev continues to be cursed, I guess.

If I really needed to use a JS library in TS, I'd have to build some sort of adapter between the two that crashes whenever the JS library (that doesn't know anything about your types) breaks the typing rules. Anything else will inevitably lead to the above "fun" kind of bugs.

[-] DrM@feddit.de 1 points 1 year ago

I don't think that this would work, there are no types anymore during runtime because everything is translated into plain js on build. TypeScript only exists during development

[-] jpeps@lemmy.world 1 points 9 months ago

Typically when creating API interfaces you'd be better off marking the inputs as unknown, and then using something like Zod to validate the types

[-] uis@lemmy.world 1 points 1 year ago

return 'myBoolean is true';

I instantly noticed this line. Shitcode is so fun.

[-] JakenVeina@lemm.ee 1 points 1 year ago
[-] AngryCommieKender@lemmy.world 7 points 1 year ago

Two questions immediately come to mind. 1) Would you buy the cyanide if it was on the list. 2) Where does one casually buy cyanide? I can't imagine a case where I'd need some, but it would be handy to know if I ever did.

[-] CanadaPlus@lemmy.sdf.org 4 points 1 year ago* (last edited 1 year ago)

I know you used to be able to get it for pest control, but maybe not anymore. You could also make it the old-fashioned way with molten washing soda. It can be used to make Prussian blue, for one thing.

Obviously take all necessary precautions, especially keeping NaCN away from acids.

[-] XTornado@lemmy.ml 3 points 1 year ago

Just one word: Apples.

this post was submitted on 14 Nov 2023
809 points (94.6% liked)

Programmer Humor

32576 readers
724 users here now

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

Rules:

founded 5 years ago
MODERATORS