23.06.2015 Views

TypeScript Language Specification v1.5

TypeScript Language Specification v1.5

TypeScript Language Specification v1.5

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

If the || expression is contextually typed (section 4.19), the operands are contextually typed by the same<br />

type. Otherwise, the left operand is not contextually typed and the right operand is contextually typed by<br />

the type of the left operand.<br />

The type of the result is the union type of the two operand types.<br />

Any Boolean Number String Other<br />

Any Any Any Any Any Any<br />

Boolean Any Boolean N | B S | B B | O<br />

Number Any N | B Number S | N N | O<br />

String Any S | B S | N String S | O<br />

Other Any B | O N | O S | O Other<br />

4.16 The Conditional Operator<br />

In a conditional expression of the form<br />

test ? expr1 : expr2<br />

the test expression may be of any type.<br />

If the conditional expression is contextually typed (section 4.19), expr1 and expr2 are contextually typed by<br />

the same type. Otherwise, expr1 and expr2 are not contextually typed.<br />

The type of the result is the union type of the types of expr1 and expr2.<br />

4.17 Assignment Operators<br />

An assignment of the form<br />

v = expr<br />

requires v to be classified as a reference (section 4.1) or as an assignment pattern (section 4.17.1). The expr<br />

expression is contextually typed (section 4.19) by the type of v, and the type of expr must be assignable to<br />

(section 3.10.4) the type of v, or otherwise a compile-time error occurs. The result is a value with the type<br />

of expr.<br />

A compound assignment of the form<br />

v ??= expr<br />

77

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!