See all glossary terms

Type

In computer programming, a type, also called data type, is a set of rules that groups values together. It describes which values are part of the same group and what operations are available for them.
Concretely, in Godot, vectors, nodes, numbers, strings, and more are types: int, float, String, Vector2, Sprite2D, Timer...
When we say that a variable is of a certain type, we mean that it can only hold values that are part of that type. For example, a variable of type int can only store integer values (whole numbers).
Often, when we use keywords like Vector2 in GDScript, we are referring to data types. For example, when we write a type hint to indicate the type of a variable or of a value returned by a function: var offset: Vector2.
However, Vector2 is also a class. In short, a class is a concrete implementation of the Vector2 type. When you construct a new Vector2 value, you are creating an instance of the Vector2 class. For example, the code Vector2(100, 200) creates a new instance of the Vector2 class with the x and y values set to 100 and 200, respectively.
This means that Vector2 is a type, but it is also a class:
  • When we write type hints or use the is or as keywords in GDScript, we are referring to the type. It is a description of the value's interface: what data it has and what operations are available on the data.
  • When we create new Vector2 values, we are referring to the class. It is a concrete implementation of the Vector2 type.
The close relationship between types and classes can be confusing. In practice, developers often use the two terms interchangeably.

See Also

Related terms in the Glossary