Strict typing
Type notations
Programming without guidance can be difficult and frustrating. If you often find yourself opening 2 Visual Studio Code tabs or perhaps constantly switching files on Studio to look at type definitions, that's usually a sign that something is not quite right.
In Luau, it is possible to add type annotations to variables, return types and parameters.
And when type annotations get too complex, the type inference simple won't work anymore, or it will default to any.
How to type components
Components are just numbers, aren't they? Well, that's technically correct. But the type checker does not need to know that. In other words, you can simulate the component's type by annotating it as a table, with a fake field holding its type.
In this code, health is typed as:
But in reality, it is a number.
Getting component data
You can get full type check support when asking for data using a typed component: