After using TypeScript there's some features that I'm terrified of that seem counter intuitive. All the following examples produce NO errors and are with every single strict TS option enabled.
-
-
Refining 'unknown' to an array produces 'Array<any>' where as 'Array<unknown>` would make more sense. Not sure if it does in other places too.pic.twitter.com/gsRa67JFFk
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
When you use as, you are telling the system that you're narrowing it yourself. It will only warn if the narrowing doesn't make sense.
-
It's doing some checking though, I just don't understand the semantics. I would understand it's existence of TS had proper type casts, like in Flow, but I can't find anything like it.
- 4 more replies
New conversation -
-
-
I think of `as` as an escape hatch that should be avoided unless there is no other option
-
I just always call them 'typecasts', since that's what they are?
- 7 more replies
New conversation -
-
-
I try and treat "as" the same as casting through a void* pointer in cpp. I wish there was a "disable using 'as' to widen types" options. Narrowing makes sense sometimes but widening is scary
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
You can treat all 'as' statements as you overruling the compiler, so you're on your own from there. It'll only stop you if it can prove you're 100% wrong. You should be able to mostly avoid them, since cases where the compiler needs overriding *should* be rare.
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 