Primitive types
Choose a numeric width, preserve a native signature, and control rounding.
| TypeScript Native | Meaning | JVM | Swift |
|---|---|---|---|
byte | Signed 8-bit integer | byte | Int8 |
short | Signed 16-bit integer | short | Int16 |
int | Signed 32-bit integer | int | Int32 |
long | Signed 64-bit integer | long | Int64 |
float | IEEE 754 binary32 | float | Float |
number, double | IEEE 754 binary64 | double | Double |
char | One UTF-16 code unit | char | UInt16 |
boolean | true or false | boolean | Bool |
An ordinary numeric literal has type number unless a declaration or call supplies a narrower context. An alias such as type Pixel = int keeps the underlying primitive type. Native primitive names are reserved in type position. number and double name the same type, so they cannot distinguish overloads. Use ECMAScript bigint for integers that need arbitrary precision.
Selecting the precision of a call
The static type of an argument selects the native Math.sqrt overload. With a float input, the result rounds to binary32.
const x: float = 2
const narrow = Math.sqrt(x) // 1.4142135381698608
const wide = Math.sqrt(double(x)) // 1.4142135623730951
const ordinary = Math.sqrt(2) // 1.4142135623730951Assigning narrow to a number preserves the already-rounded value. Widen the input before the call when the calculation needs double precision. Use explicit conversions such as float(value) to change representation. For example, float(16_777_217) yields 16_777_216. Checked casts explain how as treats type assertions.