Menu

📰
0

Luau the first coding language I learned: Type intersections for beginners

DEV Community: lua·Beey·about 1 month ago
#GlMz8Egh
#dev#class#type#intersection#strong#article
Reading 0:00
15s threshold

Table of Contents

  • Introduction
  • What is a type intersection
  • Explained like your 5
  • Notes

Introduction

This is the first post in the luau series explaining how to use a type intersection.

What is a type intersection

A type intersection in luau is Luau's AND operator but for types, an example is:


local X = workspace:WaitForChild("X") :: Part & BasePart & Instance

local TypeAnnotation: Part & BasePart & Instance = workspace:WaitForChild("TypeAnnotation") -- Type annotation

You seperate the types and to use the type intersection between types use &

Explained like your 5

A type intersection is like when your mom asks you to get a type of book that has two genres: Action and Fiction, Thats basicaly what it is but in real life

Notes

NOTE: Const has been released in luau(roblox lua) for some developers but it lacks syntax highlighting and autocomplete

Read More