Skip to main content
Version: Latest (0.56.x)

Built-in types

TypeSpec Standard Library provide some built-in types that can be used to build more complex types.

Built in types are related to each other according to the rules described in type relations.

Numeric types

TypeRangeDescription
numeric*Parent type for all numeric types
integer*A whole-number
float*A binary number
int64-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807A 64-bit integer
int32-2,147,483,648 to 2,147,483,647A 32-bit integer
int16-32,768 to 32,767A 16-bit integer
int8-128 to 127A 8-bit integer
safeint
−9007199254740991 (−(253 − 1))
to
9007199254740991 (253 − 1)
An integer that can be serialized to JSON
uint640 to 18,446,744,073,709,551,615Unsigned 64-bit integer
uint320 to 4,294,967,295Unsigned 32-bit integer
uint160 to 65,535Unsigned 16-bit integer
uint80 to 255 Unsigned 8-bit integer
float32
 ±1.5 x 1045
to
±3.4 x 1038
A 32 bit floating point number
float64
±5.0 × 10−324
to
±1.7 × 10308
A 64 bit floating point number
decimal*A decimal number
decimal12834 decimal digits with an exponent range from -6143 to 6144A 128 bit decimal number

Numeric supertypes

numeric, integer, float and decimal are types that represent any possible number in their category. For some emit targets, BigInt or BigDecimal might be an analogous type satisfying the TypeSpec types integer and decimal respectively. For other targets where the language, serialization format, or protocol does not support an analogous type, emitters may decide on a policy for emitting the numeric supertypes. This might involve picking the closest analogous type and reporting a warning when they are encountered.

Date and time types

TypeDescription
plainDateA date on a calendar without a time zone, e.g. "April 10th"
plainTimeA time on a clock without a time zone, e.g. "3:00 am"
utcDateTimeA date and time in coordinated universal time (UTC), e.g. "1985-04-12T23:20:50.52Z"
offsetDateTimeA date and time in a particular time zone, e.g. "April 10th at 3:00am in PST"
durationA duration/time period. e.g 5s, 10h

Other core types

TypeDescription
bytesA sequence of bytes
stringA sequence of textual characters
booleanBoolean with true and false values
nullNull value
Array<Element>Array model type, equivalent to Element[]
Record<Element>Model with string keys where all the values have type Element (similar to Map<string, Element> in TypeScript or Dictionary<string, Element> in .Net)
unknownA top type in TypeSpec that all types can be assigned to. Values that can have any type should be assigned this value (similar to any in JavaScript)
voidA function/operation return type indicating the function/operation doesn't return a value.
neverThe never type indicates the values that will never occur.

String types

Built-in types that are known string formats

TypeDescription
urlA url String