Module 7 · Tables and Luau types
--!strict and type annotations
Use inference and primitive annotations as Studio analysis tools, not runtime validation.
What you will learn
- Explain strict analysis and inference
- Write string, number, and boolean annotations
- Separate static types from runtime checks
- type inference
- Studio determining a type from how a value is created.
- type annotation
- An explicit type written beside a name or function boundary.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
A misspelled Coin Quest field or string passed to numeric code is cheaper to catch in the editor than during a play session.
The mental model
--!strict enables stronger analysis. Luau often infers types from values, while annotations make important contracts explicit.
Types help Studio reason about code before it runs. They do not validate untrusted network input at runtime.
New words and symbols
--!strict asks Studio to check your code for type mistakes. It is an instruction for the editor and produces no Output message.
Matching quotes such as "hello" surround a string: a piece of text. The quotation marks tell Luau where the text starts and ends.
print(...) calls the built-in print function. Put the values to show inside its parentheses; separate multiple values with commas. Read the result in Studio's Output panel.
local is read as “local”: it creates a name that is available only in the current code scope.
{ } is read as “opening and closing braces”: it creates a table value around its entries.
A colon in a declaration, such as coins: number, introduces a type annotation: the kind of value that name is allowed to hold.
= is read as “is assigned”: it evaluates the right side and stores that value in the name on the left.
. is read as “dot”: it accesses a named property or table field.
A tiny example
--!stricttype PlayerSummary = { name: string, coins: number, isReady: boolean,}local summary: PlayerSummary = { name = "Ari", coins = 4, isReady = true }print(summary.name, summary.coins)Line by line
- 1
The directive enables strict analysis for this file.
- 3
A type alias names a reusable shape.
- 4
name must be a string.
- 5
coins must be a number.
- 6
isReady must be boolean.
- 9
The annotation asks the table to match every field.
Read the code aloud
Read one statement at a time: name the value being read, what the operation does, and where its result goes. Keep identifiers exactly as written so you can find them again in the code.
Pause at calls, conditions, and loops. Explain when the body runs before moving to the next statement; use the line notes above when a symbol is unfamiliar.
Execution trace
Begin at the first executable statement. Comments and blank lines do not run; a branch chooses which block runs, and a loop may revisit its body.
Line 1: The directive enables strict analysis for this file.
Line 3: A type alias names a reusable shape.
Line 4: name must be a string.
Line 5: coins must be a number.
Line 6: isReady must be boolean.
Line 9: The annotation asks the table to match every field.
State before and after
Before running, identify the starting values and any existing Studio objects this example needs. List what you expect to change.
After your practice change, check this result: The table satisfies its declared shape and Studio has no type mismatch for the added field.
Reading or printing a value leaves it unchanged. Look for assignments, calls that change state, and property updates to explain each change you observe.
Predict before running
What would Studio flag if coins were "4"?
Try it
Mark each step after you have tried it.
Common mistake
Do not treat an annotation as a security check. Data arriving from a client or persistent store still needs runtime validation before use.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- Strict mode strengthens editor analysis.
- Inference handles many local values.
- Annotations document contracts but do not replace runtime validation.
Next: Next, you will build a typed inventory API and test its public cases.
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.