Wednesday, October 4, 2017

Assignments which accidentally use a double equals operator will not make the compiler squawk in TypeScript.

Consider this C#:

int a = 13;
int b = 42;
a = b;

 
 

And then consider introducing this typo:

int a = 13;
int b = 42;
a == b;

 
 

Alright, the compiler is going to throw a temper tantrum at that, huh? Well what if we took this TypeScript...

let a = 13;
let b = 42;
a = b;

 
 

...and screwed it up like this:

let a = 13;
let b = 42;
a == b;

 
 

Well, this may come as an unpleasant surprise (it sure did for me) but the compiler will not get cranky about this. I guess you are just dumping a comparison on a line by itself and the comparison, be it true or be it false, will just silently do nothing without any other code about it. In other words, your assignment silently fails. I guess this is legitimate JavaScript and therefore legitimate TypeScript. Fun!

No comments:

Post a Comment