Conversions

This section describes which type conversions are available.

Explicit conversions may occur as either T(v) (strict conversion) or v as T (optional conversion). The behavior of the call operator over a type may not always be a conversion depending on if T implements the static shock_proxy::call() method.

T(v)       // failure throws a TypeError
v as T     // failure returns a default value

Constant coercions

Constant coercions occur implicitly both at compile-time and runtime, converting a constant into another constant.

KindResult
undefined to flag enumerationInterned instance whose value is zero (0).
null to flag enumerationInterned instance whose value is zero (0).
undefined to T containing both undefined and nullundefined
undefined to T containing undefined and no nullundefined
undefined to T containing null and no undefinednull
null to T containing undefined but not nullundefined
null to T containing null but not undefinednull
null to T containing both undefined or nullnull
Numeric constant to * or ObjectEquivalent constant of the target type.
String constant to * or Object or union containing StringEquivalent constant of the target type.
Boolean constant to * or Object or union containing BooleanEquivalent constant of the target type.
Namespace constant to * or Object or union containing NamespaceEquivalent constant of the target type.
Type constant to * or Object or union containing ClassEquivalent constant of the target type.
Numeric constant to another compatible numeric typeNumeric constant with value coerced to target type.
Numeric constant to union containing at least one compatible numeric typeNumeric constant of the target type containing value coerced to the containing numeric type, preferring the same numeric type or otherwise the first numeric type found.
NaN to floatNaN
-Infinity to float-Infinity
+Infinity to float+Infinity

Implicit coercion

Implicit coercions occur implicitly both at compile-time and runtime, after trying a constant coercion.

KindResult
From *
To *
From numeric type to compatible numeric type
To covariant (includes base classes, implemented interfaces, unions and inherited record type)
From union to compatible union
From union member to union
From structural function type to another compatible function type

Note: interface types inherit Object.

Explicit conversions

Explicit conversions occur when resolving v as T or T(v), after trying an implicit coercion.

KindResult
To contravariant (from interface to interface subtype, from class to subclass, or record type subtype)
To union member
From * or Object to interface
To another [T] typeAn array filtering out incompatible elements.
String to enumerationIdentification of an enumeration variant by its String name.
Number to enumeration (using the same numeric type)For regular enumerations, identifies a variant by its numeric value. For flag enumerations, identifies variant bits.
To StringFor undefined, returns "undefined"; for null, returns "null"; for other types, invokes toString().
To BooleanEvaluates truthy value.
To NumberForced conversion to double-precision floating point.
To floatForced conversion to single-precision floating point.
To decimalForced conversion to 128-bit decimal number.
To intForced conversion to 32-bit signed integer.
To uintForced conversion to 32-bit unsigned uninteger.
To BigIntForced conversion to an arbitrary range integer.
Record type into equivalent record type of non-uniform field order
From type parameter

Note: interface types inherit Object.