Built In Types: Introduction
This section covers the different built-in types available in Hack.
Primitive Types
Hack has the following primitive types: bool, int, float, string, and null.
Union Types
Hack supports union types, like:
- num, where
int
andfloat
are subtypes ofnum
, and - arraykey, where
int
andstring
are subtypes ofarraykey
.
The Super Type
Hack's super type is mixed, which represents any value. All other types are subtypes of mixed
.
A few things to know when working with mixed
as a type:
- The opposite of
mixed
is nothing, a special type at the "bottom" of all other types. mixed
is equivalent to?nonnull
. nonnull is a type that represents any value exceptnull
.
Hack Arrays
There are three types of Hack Arrays. They are: vec, keyset, and dict.
Though not built-in as types, other alternatives exist in Hack Collections.
Other Built-In Types
Hack has other built-in types too, like: enum (with enum class and enum class labels), shape, and tuples.
Function Return Types
Other types like noreturn and void are only valid as function return types .
Special Types
These last few types are special in their utility and/or versatility: classname, dynamic, and this.
Thank You!
Thank You! If you'd like to share more feedback, please file an issue.