As you might know, it’s possible to help Luau out with classes, using the : operator, like this: local item:Instance = Instance.new("Part")
------------------------ ^ -----------------------------
Well, today I came across some interesting “classes” - it seems like a couple of functions have been somehow interpreted as classes - a bunch of arithmetic operations, “len” (which I assume is a length function), and some other ones I can’t quite identify, such as “le”, “lt”, “keyof”, and a few variations of these.
Also, pretty much all of these are generic types.
What could these be? I don’t remember coming across them before, so they must be new. Or maybe it’s from other sources, like plugins?
Let me know!
(I would provide screenshots, but the autocomplete panel hides when I try to. Sorry.)
I suppose these have to do with defining types in Roblox Studio. They are not types per se, but they are helpers for types. I haven’t used them at all yet though, so I might be wrong.
Those aren’t classes; they are type functions. They’re useful functions you can use within type annotations to enhance them.
It’s important to note that type annotations are not just for Roblox classes; they are for any type within the language, such as string, number, et cetera. All Roblox classes are defined as types in the typechecker, but not all types in the typechecker are Roblox classes.
Well first of all, a class constructs an object from the blueprint (which is the class), and since Luau doesn’t actually have real classes, you simulate them with metatables and attach constructor function which is usually new, Instance being the class, and the constructed object is of type Instance local instance = Instance.new("Part"), in this line, it inferrs the type Instance, and which autocomplete starts to suggest properties and methods of that class.
Asumming you don’t have the variable initialized: local myPart;, but still need autocomplete in the very next lines, since you didn’t assign any value, it inferrs it to be nil, a solution to this is typechecking, a way to mark your variable as a specific type.
If you had:
local myPart: Instance
myPart.P
as you wrote P, the autocomplete will suggest you every field (method, property) of the Instance class and it’s inheritence. An example is you will see Parent property suggested.