Timon3 4 days ago

Many, if not most, of these occurrences can be made safe. It's very rare that I need `as`, and even more rare that I can't actually check the relevant properties at runtime to ensure the code path is valid.

It's on you to ensure that you don't misuse `as`. If I could choose between current TS, and a "safer" one that's less expressive in complex cases, I'd choose the current one any day of the week.

1
yencabulator 4 days ago

"Typescript can be made safe" is the "C++ has a subset that is good" argument. Meh.

Timon3 4 days ago

Almost every language has some way to do stupid things. Say you're working in C# - you can forcefully cast almost anything to almost anything else, just like in TS. So according to you, C# is just as bad as TS in this respect, right?

neonsunset 4 days ago

You can only do this with `unsafe { }` or `Unsafe.As/.BitCast`. Casts from/to `object` are type-safe even though may not be very user-friendly or good use of the type system in general.

yencabulator 4 days ago

If that's a thing commonly needed for basic operations like letting your event handler actually access the event details, then very much yes.

Sane languages have a downcast mechanism that doesn't pretend it succeeds every time.

Timon3 4 days ago

Weird, I don't need to do that.

Also weird that Typescript has exactly the mechanism you're talking about. Why are you acting like it doesn't?