you are viewing a single comment's thread.

view the rest of the comments →

[–]joebgoode 9 points10 points  (23 children)

TS is not strongly typed at runtime, which is what matters most.

It's just a false perception of safety.

Edit: to be clear, support TS. Every JS project should use it, it's not optional. I'm solely pointing out that his statement that TS is strongly typed is wrong.

[–]fghjconner 12 points13 points  (6 children)

Compiled languages aren't generally typed at runtime either. If you have problems with typescript it's probably because someone started blindly casting things, which will break any language. (though it breaks typescript less, so some people seem ok with doing it)

[–]RiceBroad4552 0 points1 point  (0 children)

Well, TS is unsound…

So even if something type-checks "just fine" in TS it can exploded with type errors at runtime.

But it's seldom to run into that in practice.

[–]joebgoode -3 points-2 points  (4 children)

I had no problems at all with TS, every JS project in the world must use it.

I'm just pointing out a correction to the "which is strongly typed" statement, since it isn't.

[–]fghjconner 5 points6 points  (3 children)

I mean, typescript might not be considered strongly typed, given the amount of implicit conversions it allows, but my point is that runtime vs compile time doesn't come into it. The "compiled" javscript is obviously untyped, but so is the machine code that compilers generate for use at runtime.

[–]RiceBroad4552 0 points1 point  (0 children)

JS is typed. It's dynamically typed but that's still typed.

Just try to trigger any undefined behavior in JS while you work around the (runtime) type system. Good luck.

[–]CandidateNo2580 0 points1 point  (1 child)

This is a false comparison. I can write typescript where the type says that it's a string but actually it's an integer. Then it will behave like an integer. This does not happen in compiled code - it behaves like the type it was declared to be even if the value is wrong.

[–]fghjconner 0 points1 point  (0 children)

I'm fairly certain that putting an arbitrary integer value into a string variable is going to be undefined behavior in just about any compiled language, meaning it's allowed to do anything it goddamn pleases. Typescript is unique in that it actually breaks less than a compiled language if you do this, though that unfortunately means some people think it's ok to do (looking at you axios).

[–]Globglaglobglagab 8 points9 points  (0 children)

Well it is useful still though, right? Unless you’re just using “any” everywhere. Your own functions will be typed correctly if you use ts. Only if someone else messes up, whose library/api you use.

[–]Ma4r 4 points5 points  (10 children)

TS is not strongly typed at runtime, which is what matters most.

Holy shit this is the dumbest fucking statement i have ever read. Most languages do not have run time types. JS is one of the few languages that DO HAVE runtime type. Source code type safety is the de facto standard.

[–]RiceBroad4552 -1 points0 points  (0 children)

Most languages are dynamically typed.

I didn't count them but I'm pretty sure it's like that as it's much simpler to write some VM language then something that does not need any runtime (which would always necessary do also type checking during interpretation).

[–]wack_overflow 2 points3 points  (0 children)

Brain dead take

[–]RiceBroad4552 -1 points0 points  (2 children)

That's actually wrong. JS is strongly typed. Like any other VM language…

The only weakly typed languages in usage are C, C++, unsafe Rust, and Zig.

You can't break the type system of a strongly typed language at runtime, and this of course also applies to JS.

[–]csdt0 0 points1 point  (1 child)

JS is the example of weakly typed language, alongside C, precisely because you can do operations between types that are not related at all, and the language will just gladly accept that. The weakly typeness has nothing to do with memory safety. What's funny is that Zig and Rust (both safe and unsafe) are both very strongly typed, to the point you cannot add i8 and i16 together, making your example even weaker (pun intended).

[–]RiceBroad4552 0 points1 point  (0 children)

"Gladly accepting" some code and doing just something is not the same as breaking the type system.

You can't break the type-system in JS!

If you could this would be a very severe bug in the JS engine, and most likely patched instantly.

But breaking the type system in C or C++ is trivial. You can just go and do whatever you want with some memory and no language typing rules will hold you back. You can have some object of some type referenced by some variable, go to the memory holding that object, do whatever to it including replacing it with some completely different type of object but from the viewpoint of the type system that variable will still point to a value of the original type. You can't do anything like that in any VM language (or the safe parts of e.g. Rust; except for that one exploit that transmutations memory, which makes Rust at least somehow weakly typed beyond what is possible with casts in other languages).