peyremorgan,

@lil5 @evrys Sorry, meant to reply later in the day and forgot 😶

The browser will always be way more lenient than the type system, and that's by design.

The browser is on the side of the user, and will do whatever it takes to produce a usable web page. That means ignoring mismatched HTML tags, JS errors, etc...
By the time the page source hits the engine, the developers are likely too far away (in both space and time) to do anything about these errors, and you would just be punishing end users by being too strict at runtime.

The TS compiler on the other hand knows it's talking directly to the dev, and can be arbitrarily anal about typing, syntax errors, etc...
In fact it has to be, since its job is to protect developers from their own mistakes.

Let's take clearTimeout(myVar) as an example (where myVar can be null).
At runtime : no big deal. let's just ignore it. the user probably would rather have a semi functional web page than an error message they can't do anything about.
At compile time : tsc has to warn you. You gave the type system conflicting information about your variable, so it has to assume it's a bug. Maybe you forgot to setInterval somewhere. Maybe you didn't think about some edge case or error condition. Or maybe it's completely fine. But this is the only chance the compiler has to tell you "look, what would happen if myVar was null here?"

  • All
  • Subscribed
  • Moderated
  • Favorites
  • typescript
  • DreamBathrooms
  • mdbf
  • ethstaker
  • magazineikmin
  • GTA5RPClips
  • rosin
  • thenastyranch
  • Youngstown
  • osvaldo12
  • slotface
  • khanakhh
  • kavyap
  • InstantRegret
  • Durango
  • JUstTest
  • everett
  • cisconetworking
  • Leos
  • normalnudes
  • cubers
  • modclub
  • ngwrru68w68
  • tacticalgear
  • provamag3
  • anitta
  • tester
  • megavids
  • lostlight
  • All magazines