Better checking for null/undefined in operands of expressions
TypeScript 2.2 improves checking of nullable operands in expressions. Specifically, these are now flagged as errors:
- If either operand of a
+
operator is nullable, and neither operand is of typeany
orstring
. - If either operand of a
-
,,
*
,/
,%
,<<
,>>
,>>>
,&
,|
, or^
operator is nullable. - If either operand of a
<
,>
,<=
,>=
, orin
operator is nullable. - If the right operand of an
instanceof
operator is nullable. - If the operand of a
+
,-
,~
,++
, or—
unary operator is nullable.An operand is considered nullable if the type of the operand isnull
orundefined
or a union type that includesnull
orundefined
. Note that the union type case only only occurs in—strictNullChecks
mode becausenull
andundefined
disappear from unions in classic type checking mode.