Skip to content

Commit 4849fa7

Browse files
committed
docs: reference aliasing document from main tutorial
1 parent d0a3717 commit 4849fa7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

docs/tutorial.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,18 +456,23 @@ local p: Point = { x = 100, y = 100 }
456456
This, however, won't work:
457457

458458
```lua
459-
local p1 = { x = 100, y = 100 }
460-
local p2: Point = p1 -- Error!
459+
local record Vector
460+
x: number
461+
y: number
462+
end
463+
464+
local v1: Vector = { x = 100, y = 100 }
465+
local p2: Point = v1 -- Error!
461466
```
462467

463468
Just because a table has fields with the same names and types, it doesn't mean
464-
that it is a Point. A Distance could also be defined as fields x and y, but a
465-
distance is not a point.
469+
that it is a Point. This is because records in Teal are [nominal
470+
types](aliasing.md).
466471

467472
You can always force a type, though, using the `as` operator:
468473

469474
```lua
470-
local p2 = p1 as Point -- Ok, I'll trust you...
475+
local p2 = v1 as Point -- Teal goes "ok, I'll trust you..."
471476
```
472477

473478
Note we didn't even have to declare the type of p2. The `as` expression resolves

0 commit comments

Comments
 (0)