Skip to Content
Language reference

Primitive types

Choose a numeric width, preserve a native signature, and control rounding.

TypeScript NativeMeaningJVMSwift
byteSigned 8-bit integerbyteInt8
shortSigned 16-bit integershortInt16
intSigned 32-bit integerintInt32
longSigned 64-bit integerlongInt64
floatIEEE 754 binary32floatFloat
number, doubleIEEE 754 binary64doubleDouble
charOne UTF-16 code unitcharUInt16
booleantrue or falsebooleanBool

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.4142135623730951

Assigning 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.

On this page