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.
-
-
If your 12 uses of type predicates is similar to your example of a string primitive, it’s actually safer to move the typeof inline as a type guard. The predicates are only useful for nested objects. It would be great if they were safe and forced an explicit cast to be unsafe.
-
Here's a few instances of my usages of type predicates. It's not really an option to inline all of these, especially `isStatement`. They're essential for refinements of very large unions.pic.twitter.com/XC2FWCZls0
- 2 more replies
New conversation -
-
-
'as' is an escape hatch much like 'any'—“don’t bother me, just let me write this.” It lets you cast up or down, just not to an unrelated type. It can almost always be avoided. 1/2
-
If you just want a “safe” cast (well, safe if we naively assume mutable properties are covariantly typed), you can declare a new variable: let a: string; let b: string | number = a;
let c: "foo" = a;
c is an unsafe downcast and is caught as such
End of conversation
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 