Skip to main content
The number type in TypeScript is a primitive data type that represents both integer and floating-point values. Inheriting JavaScript’s numeric implementation, TypeScript evaluates all number values as IEEE 754 double-precision 64-bit floating-point formats. There is no distinct type for integers (e.g., int or float) within the standard number type.

Literal Representations

TypeScript supports strict typing for base numeral systems and scientific notation using specific literal formats:

Numeric Separators

To improve the readability of large numeric literals, TypeScript supports the ECMAScript numeric separator feature. Underscores (_) can be used to visually group digits, but they must be placed strictly between two digits. They cannot appear at the beginning or end of a literal, adjacent to a decimal point, adjacent to a base prefix, or consecutively. These separators are stripped out during compilation and do not affect the underlying value.

Special Numeric Values

The number type encompasses several special global properties that result from specific mathematical operations or represent boundary limits:

Precision and Bounds

Because number relies on a 64-bit floating-point format, it can only safely represent integers between -(2^53 - 1) and 2^53 - 1.
Integers outside this boundary will experience precision loss. For arbitrary-precision integers, TypeScript provides a distinct bigint primitive, which is not strictly compatible with number without explicit coercion.

Primitive vs. Wrapper Object

TypeScript distinguishes between the lowercase number primitive and the uppercase Number global wrapper object. Type annotations should always use the lowercase number to avoid assigning an object reference where a primitive value is expected.
Tired of Poor TypeScript Skills? Fix That With Deep Grasping!Learn More