So that next time your coworker uses the wrong type, the compiler can scream at him: “NO I WONT COMPILE THIS YOU DUMBASS, LOOK JOHN SAID ON LINE 863 THAT IT SHOULD BE A DOUBLE, NOT A FLOAT FOR FUCK SAKE”
💯% accurate. funny how the typescript developer thinks this is some kind of “gotcha!”… like maybe just try a language besides typescript and find out for yourself 😆
That’s such a weird take. Who cares what another language does? Your complaint was about typescript. Which lets the programmer decide what this should be. As you could have known.
But most likely it was just trolling. On the plus side, at least now I know that the rigid minded devs came here too, and took their righteousness with them.
Yeah, you’re right. Lemmy is reddit, but worse, and very small. I have no doubt your contributions will keep it that way. I’m going to delete my account. This is just not worth anybody’s time and attention.
Exactly. Most languages I know of that allow this at all will coerce the “1” to an integer and give x = 2. They get away with this because they define the “+” operator as taking numbers only as arguments, so if you hand them x = x + "cheese" they’ll error out.
I’m not sure if you’re being rhetorical or not, but “string|number” is definitely correct here. A computer could definitely figure this out, but typing is for the benefit of the coders more than the code itself. It’s basically functional documentation
That’s TypeScript’s whole point. It’s not for the computer, it’s for the programmer. It’s to avoid you assigning a string to something you elsewhere assume to contain a number. In Typescript, there’s just no solution for this, except requiring the programmer to specify the type. It can’t be inferred flawlessly.
Yeah that’s what I’m saying, I hate it when coworkers will assign everything as “any” just to avoid the scary red squigglies. Oh well I guess that’s what code reviews are for 🙃
i like when my strongly typed language can type itself, why should i have to type extra words because the compiler is stupid?
So that next time your coworker uses the wrong type, the compiler can scream at him: “NO I WONT COMPILE THIS YOU DUMBASS, LOOK JOHN SAID ON LINE 863 THAT IT SHOULD BE A DOUBLE, NOT A FLOAT FOR FUCK SAKE”
Tell me you are a Java dev without telling me you are a a Java dev 😂
As a JS dev, I can only wish we had those types 🥲
you can still have that without having to declare the type manually. check out Swift or OCaml for example
So what’s the type of x in
number? string? string|number? any?
The ts compiler can make a fair amount of inferences, but at some points you need to nail down the type. Is that so bad?
Type error unless there’s an implementation of
+
that specifies adding together and integer and a string.💯% accurate. funny how the typescript developer thinks this is some kind of “gotcha!”… like maybe just try a language besides typescript and find out for yourself 😆
That’s such a weird take. Who cares what another language does? Your complaint was about typescript. Which lets the programmer decide what this should be. As you could have known.
But most likely it was just trolling. On the plus side, at least now I know that the rigid minded devs came here too, and took their righteousness with them.
“brought” 😏
my complaint is that typescript is stupid, yes. so why wouldn’t i compare to what other languages do that is less stupid?
on the plus side, at least now i know that the ad-hominem minded devs came here too, and brought their righteousness with them.
Yeah, you’re right. Lemmy is reddit, but worse, and very small. I have no doubt your contributions will keep it that way. I’m going to delete my account. This is just not worth anybody’s time and attention.
OCaml 😍
Exactly. Most languages I know of that allow this at all will coerce the “1” to an integer and give x = 2. They get away with this because they define the “+” operator as taking numbers only as arguments, so if you hand them
x = x + "cheese"
they’ll error out.In the world of C and pointer arithmetic this makes perfect sense /s
I’m not sure if you’re being rhetorical or not, but “string|number” is definitely correct here. A computer could definitely figure this out, but typing is for the benefit of the coders more than the code itself. It’s basically functional documentation
That’s TypeScript’s whole point. It’s not for the computer, it’s for the programmer. It’s to avoid you assigning a string to something you elsewhere assume to contain a number. In Typescript, there’s just no solution for this, except requiring the programmer to specify the type. It can’t be inferred flawlessly.
Yeah that’s what I’m saying, I hate it when coworkers will assign everything as “any” just to avoid the scary red squigglies. Oh well I guess that’s what code reviews are for 🙃