4 Expressions
This chapter describes the manner in which TypeScript provides type inference and type checking for JavaScript expressions. TypeScript’s type analysis occurs entirely at compile-time and adds no run-time overhead to expression evaluation.
TypeScript’s typing rules define a type for every expression construct. For example, the type of the literal 123 is the Number primitive type, and the type of the object literal { a: 10, b: “hello” } is { a: number; b: string; }. The sections in this chapter describe these rules in detail.
In addition to type inference and type checking, TypeScript augments JavaScript expressions with the following constructs:
- Optional parameter and return type annotations in function expressions and arrow functions.
- Type arguments in function calls.
- Type assertions.
Unless otherwise noted in the sections that follow, TypeScript expressions and the JavaScript expressions generated from them are identical.