File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -456,18 +456,23 @@ local p: Point = { x = 100, y = 100 }
456
456
This, however, won't work:
457
457
458
458
``` 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!
461
466
```
462
467
463
468
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 ) .
466
471
467
472
You can always force a type, though, using the ` as ` operator:
468
473
469
474
``` 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..."
471
476
```
472
477
473
478
Note we didn't even have to declare the type of p2. The ` as ` expression resolves
You can’t perform that action at this time.
0 commit comments